@@ -537,13 +537,28 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
537
537
match self_ty. value . value . sty {
538
538
ty:: Dynamic ( ref data, ..) => {
539
539
if let Some ( p) = data. principal ( ) {
540
- let InferOk { value : instantiated_self_ty, obligations : _ } =
541
- self . fcx . probe_instantiate_query_response (
542
- self . span , & self . orig_steps_var_values , self_ty)
543
- . unwrap_or_else ( |_| {
544
- span_bug ! ( self . span, "{:?} was applicable but now isn't?" , self_ty)
545
- } ) ;
546
- self . assemble_inherent_candidates_from_object ( instantiated_self_ty) ;
540
+ // Subtle: we can't use `instantiate_query_response` here: using it will
541
+ // commit to all of the type equalities assumed by inference going through
542
+ // autoderef (see the `method-probe-no-guessing` test).
543
+ //
544
+ // However, in this code, it is OK if we end up with an object type that is
545
+ // "more general" than the object type that we are evaluating. For *every*
546
+ // object type `MY_OBJECT`, a function call that goes through a trait-ref
547
+ // of the form `<MY_OBJECT as SuperTraitOf(MY_OBJECT)>::func` is a valid
548
+ // `ObjectCandidate`, and it should be discoverable "exactly" through one
549
+ // of the iterations in the autoderef loop, so there is no problem with it
550
+ // being discoverable in another one of these iterations.
551
+ //
552
+ // Using `instantiate_canonical_with_fresh_inference_vars` on our
553
+ // `Canonical<QueryResponse<Ty<'tcx>>>` and then *throwing away* the
554
+ // `CanonicalVarValues` will exactly give us such a generalization - it
555
+ // will still match the original object type, but it won't pollute our
556
+ // type variables in any form, so just do that!
557
+ let ( QueryResponse { value : generalized_self_ty, .. } , _ignored_var_values) =
558
+ self . fcx . instantiate_canonical_with_fresh_inference_vars (
559
+ self . span , & self_ty) ;
560
+
561
+ self . assemble_inherent_candidates_from_object ( generalized_self_ty) ;
547
562
self . assemble_inherent_impl_candidates_for_type ( p. def_id ( ) ) ;
548
563
}
549
564
}
0 commit comments