@@ -81,11 +81,25 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
81
81
let rcvr_substs = self . fresh_receiver_substs ( self_ty, & pick) ;
82
82
let all_substs = self . instantiate_method_substs ( & pick, segment, rcvr_substs) ;
83
83
84
- debug ! ( "all_substs={ :?}" , all_substs) ;
84
+ debug ! ( "rcvr_substs={rcvr_substs :?}, all_substs={all_substs:?}" ) ;
85
85
86
86
// Create the final signature for the method, replacing late-bound regions.
87
87
let ( method_sig, method_predicates) = self . instantiate_method_sig ( & pick, all_substs) ;
88
88
89
+ // If there is a `Self: Sized` bound and `Self` is a trait object, it is possible that
90
+ // something which derefs to `Self` actually implements the trait and the caller
91
+ // wanted to make a static dispatch on it but forgot to import the trait.
92
+ // See test `src/test/ui/issue-35976.rs`.
93
+ //
94
+ // In that case, we'll error anyway, but we'll also re-run the search with all traits
95
+ // in scope, and if we find another method which can be used, we'll output an
96
+ // appropriate hint suggesting to import the trait.
97
+ let filler_substs = rcvr_substs
98
+ . extend_to ( self . tcx , pick. item . def_id , |def, _| self . tcx . mk_param_from_def ( def) ) ;
99
+ let illegal_sized_bound = self . predicates_require_illegal_sized_bound (
100
+ & self . tcx . predicates_of ( pick. item . def_id ) . instantiate ( self . tcx , filler_substs) ,
101
+ ) ;
102
+
89
103
// Unify the (adjusted) self type with what the method expects.
90
104
//
91
105
// SUBTLE: if we want good error messages, because of "guessing" while matching
@@ -106,16 +120,6 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
106
120
// Make sure nobody calls `drop()` explicitly.
107
121
self . enforce_illegal_method_limitations ( & pick) ;
108
122
109
- // If there is a `Self: Sized` bound and `Self` is a trait object, it is possible that
110
- // something which derefs to `Self` actually implements the trait and the caller
111
- // wanted to make a static dispatch on it but forgot to import the trait.
112
- // See test `src/test/ui/issue-35976.rs`.
113
- //
114
- // In that case, we'll error anyway, but we'll also re-run the search with all traits
115
- // in scope, and if we find another method which can be used, we'll output an
116
- // appropriate hint suggesting to import the trait.
117
- let illegal_sized_bound = self . predicates_require_illegal_sized_bound ( & method_predicates) ;
118
-
119
123
// Add any trait/regions obligations specified on the method's type parameters.
120
124
// We won't add these if we encountered an illegal sized bound, so that we can use
121
125
// a custom error in that case.
0 commit comments