@@ -237,7 +237,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
237
237
match * source {
238
238
CandidateSource :: ImplSource ( impl_did) => {
239
239
// Provide the best span we can. Use the item, if local to crate, else
240
- // the impl, if local to crate (item may be defaulted), else the call site .
240
+ // the impl, if local to crate (item may be defaulted), else nothing .
241
241
let item = impl_item ( fcx. tcx ( ) , impl_did, item_name)
242
242
. or_else ( || {
243
243
trait_item (
@@ -246,8 +246,9 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
246
246
item_name
247
247
)
248
248
} ) . unwrap ( ) ;
249
- let impl_span = fcx. tcx ( ) . map . def_id_span ( impl_did, span) ;
250
- let item_span = fcx. tcx ( ) . map . def_id_span ( item. def_id ( ) , impl_span) ;
249
+ let note_span = fcx. tcx ( ) . map . span_if_local ( item. def_id ( ) ) . or_else ( || {
250
+ fcx. tcx ( ) . map . span_if_local ( impl_did)
251
+ } ) ;
251
252
252
253
let impl_ty = check:: impl_self_ty ( fcx, span, impl_did) . ty ;
253
254
@@ -259,11 +260,17 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
259
260
}
260
261
} ;
261
262
262
- span_note ! ( err, item_span,
263
- "candidate #{} is defined in an impl{} for the type `{}`" ,
264
- idx + 1 ,
265
- insertion,
266
- impl_ty) ;
263
+ let note_str = format ! ( "candidate #{} is defined in an impl{} \
264
+ for the type `{}`",
265
+ idx + 1 ,
266
+ insertion,
267
+ impl_ty) ;
268
+ if let Some ( note_span) = note_span {
269
+ // We have a span pointing to the method. Show note with snippet.
270
+ err. span_note ( note_span, & note_str) ;
271
+ } else {
272
+ err. note ( & note_str) ;
273
+ }
267
274
}
268
275
CandidateSource :: TraitSource ( trait_did) => {
269
276
let item = trait_item ( fcx. tcx ( ) , trait_did, item_name) . unwrap ( ) ;
0 commit comments