@@ -165,6 +165,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
165165 {
166166 return true ;
167167 }
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+ }
168177 }
169178 hir:: ExprKind :: Struct ( qpath, fields, ..) => {
170179 if let Res :: Def ( DefKind :: Struct | DefKind :: Variant , variant_def_id) =
@@ -214,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
214223 qpath : & hir:: QPath < ' tcx > ,
215224 ) -> bool {
216225 match qpath {
217- hir:: QPath :: Resolved ( _ , path) => {
226+ hir:: QPath :: Resolved ( self_ty , path) => {
218227 for segment in path. segments . iter ( ) . rev ( ) {
219228 if let Res :: Def ( kind, def_id) = segment. res
220229 && !matches ! ( kind, DefKind :: Mod | DefKind :: ForeignMod )
@@ -223,11 +232,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
223232 return true ;
224233 }
225234 }
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+ }
226247 }
227- hir:: QPath :: TypeRelative ( _ , segment) => {
248+ hir:: QPath :: TypeRelative ( self_ty , segment) => {
228249 if self . point_at_generic_if_possible ( error, def_id, param, segment) {
229250 return true ;
230251 }
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+ }
231263 }
232264 _ => { }
233265 }
0 commit comments