about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-05-03 04:23:13 -0700
committerbors <bors@rust-lang.org>2016-05-03 04:23:13 -0700
commit3157691f963a86776cb7e6a7842f566032890aba (patch)
tree392d940b638c90c0a14ef243a2b8112b3fcd2446
parent7d8100a068151512774caf15a6a88766ca9cf434 (diff)
parent780f725176e0fb8f37ef67564dd9ff1ee01f29c2 (diff)
downloadrust-3157691f963a86776cb7e6a7842f566032890aba.tar.gz
rust-3157691f963a86776cb7e6a7842f566032890aba.zip
Auto merge of #33330 - birkenfeld:issue-29121, r=Manishearth
typeck: when suggesting associated fns, do not show call site as fallback

In case we cannot produce a span for the location of the definition, just do not show a span at all.

cc: #29121
-rw-r--r--src/librustc_typeck/check/method/suggest.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 4ba8f2c9d62..fab3bb60e0b 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -233,7 +233,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
             match *source {
                 CandidateSource::ImplSource(impl_did) => {
                     // Provide the best span we can. Use the item, if local to crate, else
-                    // the impl, if local to crate (item may be defaulted), else the call site.
+                    // the impl, if local to crate (item may be defaulted), else nothing.
                     let item = impl_item(fcx.tcx(), impl_did, item_name)
                         .or_else(|| {
                             trait_item(
@@ -242,8 +242,9 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                                 item_name
                             )
                         }).unwrap();
-                    let impl_span = fcx.tcx().map.def_id_span(impl_did, span);
-                    let item_span = fcx.tcx().map.def_id_span(item.def_id(), impl_span);
+                    let note_span = fcx.tcx().map.span_if_local(item.def_id()).or_else(|| {
+                        fcx.tcx().map.span_if_local(impl_did)
+                    });
 
                     let impl_ty = check::impl_self_ty(fcx, span, impl_did).ty;
 
@@ -255,11 +256,17 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                         }
                     };
 
-                    span_note!(err, item_span,
-                               "candidate #{} is defined in an impl{} for the type `{}`",
-                               idx + 1,
-                               insertion,
-                               impl_ty);
+                    let note_str = format!("candidate #{} is defined in an impl{} \
+                                            for the type `{}`",
+                                           idx + 1,
+                                           insertion,
+                                           impl_ty);
+                    if let Some(note_span) = note_span {
+                        // We have a span pointing to the method. Show note with snippet.
+                        err.span_note(note_span, &note_str);
+                    } else {
+                        err.note(&note_str);
+                    }
                 }
                 CandidateSource::TraitSource(trait_did) => {
                     let item = trait_item(fcx.tcx(), trait_did, item_name).unwrap();