@@ -237,7 +237,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
237237 match * source {
238238 CandidateSource :: ImplSource ( impl_did) => {
239239 // 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 .
241241 let item = impl_item ( fcx. tcx ( ) , impl_did, item_name)
242242 . or_else ( || {
243243 trait_item (
@@ -246,8 +246,9 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
246246 item_name
247247 )
248248 } ) . 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+ } ) ;
251252
252253 let impl_ty = check:: impl_self_ty ( fcx, span, impl_did) . ty ;
253254
@@ -259,11 +260,17 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
259260 }
260261 } ;
261262
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+ }
267274 }
268275 CandidateSource :: TraitSource ( trait_did) => {
269276 let item = trait_item ( fcx. tcx ( ) , trait_did, item_name) . unwrap ( ) ;
0 commit comments