From 4142d7bb890b631bae5d7872dce3e1c1a6816e9f Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Wed, 31 May 2017 23:48:19 -0700 Subject: Use callsite's span for macro calls on suggestion When suggesting an appropriate mutability for a macro call, use the call span instead of the expanded macro's span. --- src/librustc_errors/emitter.rs | 8 +++----- src/librustc_errors/lib.rs | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index a9645f9ab7b..f820ea4c5e1 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -705,11 +705,9 @@ impl EmitterWriter { if *sp == DUMMY_SP { continue; } - if cm.span_to_filename(sp.clone()).contains("macros>") { - let v = sp.macro_backtrace(); - if let Some(use_site) = v.last() { - before_after.push((sp.clone(), use_site.call_site.clone())); - } + let call_sp = cm.call_span_if_macro(*sp); + if call_sp != *sp { + before_after.push((sp.clone(), call_sp)); } for trace in sp.macro_backtrace().iter().rev() { // Only show macro locations that are local diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index d1aaaf4ba7b..8d5e9e776ed 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -102,6 +102,7 @@ pub trait CodeMapper { fn span_to_string(&self, sp: Span) -> String; fn span_to_filename(&self, sp: Span) -> FileName; fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option; + fn call_span_if_macro(&self, sp: Span) -> Span; } impl CodeSuggestion { -- cgit 1.4.1-3-g733a5