@@ -165,6 +165,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
165
165
{
166
166
return true ;
167
167
}
168
+ // Handle `Self` param specifically, since it's separated in
169
+ // the method call representation
170
+ if self_param_to_point_at. is_some ( ) {
171
+ error. obligation . cause . span = receiver
172
+ . span
173
+ . find_ancestor_in_same_ctxt ( error. obligation . cause . span )
174
+ . unwrap_or ( receiver. span ) ;
175
+ return true ;
176
+ }
168
177
}
169
178
hir:: ExprKind :: Struct ( qpath, fields, ..) => {
170
179
if let Res :: Def ( DefKind :: Struct | DefKind :: Variant , variant_def_id) =
@@ -214,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
214
223
qpath : & hir:: QPath < ' tcx > ,
215
224
) -> bool {
216
225
match qpath {
217
- hir:: QPath :: Resolved ( _ , path) => {
226
+ hir:: QPath :: Resolved ( self_ty , path) => {
218
227
for segment in path. segments . iter ( ) . rev ( ) {
219
228
if let Res :: Def ( kind, def_id) = segment. res
220
229
&& !matches ! ( kind, DefKind :: Mod | DefKind :: ForeignMod )
@@ -223,11 +232,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
223
232
return true ;
224
233
}
225
234
}
235
+ // Handle `Self` param specifically, since it's separated in
236
+ // the path representation
237
+ if let Some ( self_ty) = self_ty
238
+ && let ty:: GenericArgKind :: Type ( ty) = param. unpack ( )
239
+ && ty == self . tcx . types . self_param
240
+ {
241
+ error. obligation . cause . span = self_ty
242
+ . span
243
+ . find_ancestor_in_same_ctxt ( error. obligation . cause . span )
244
+ . unwrap_or ( self_ty. span ) ;
245
+ return true ;
246
+ }
226
247
}
227
- hir:: QPath :: TypeRelative ( _ , segment) => {
248
+ hir:: QPath :: TypeRelative ( self_ty , segment) => {
228
249
if self . point_at_generic_if_possible ( error, def_id, param, segment) {
229
250
return true ;
230
251
}
252
+ // Handle `Self` param specifically, since it's separated in
253
+ // the path representation
254
+ if let ty:: GenericArgKind :: Type ( ty) = param. unpack ( )
255
+ && ty == self . tcx . types . self_param
256
+ {
257
+ error. obligation . cause . span = self_ty
258
+ . span
259
+ . find_ancestor_in_same_ctxt ( error. obligation . cause . span )
260
+ . unwrap_or ( self_ty. span ) ;
261
+ return true ;
262
+ }
231
263
}
232
264
_ => { }
233
265
}
0 commit comments