rustc_errors: hide "in this macro invocation" when redundant, more explicitly.
This commit is contained in:
parent
5eaa9a150d
commit
ab080973cb
9 changed files with 53 additions and 68 deletions
|
@ -32,7 +32,7 @@ impl Emitter for AnnotateSnippetEmitterWriter {
|
|||
let mut children = diag.children.clone();
|
||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
|
||||
|
||||
self.render_multispans_macro_backtrace_and_fix_extern_macros(
|
||||
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||
&self.source_map,
|
||||
&mut primary_span,
|
||||
&mut children,
|
||||
|
|
|
@ -271,7 +271,7 @@ pub trait Emitter {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_multispans_macro_backtrace_and_fix_extern_macros(
|
||||
fn fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||
&self,
|
||||
source_map: &Option<Lrc<SourceMap>>,
|
||||
span: &mut MultiSpan,
|
||||
|
@ -279,10 +279,16 @@ pub trait Emitter {
|
|||
level: &Level,
|
||||
backtrace: bool,
|
||||
) {
|
||||
self.render_multispans_macro_backtrace(source_map, span, children, backtrace);
|
||||
let mut external_spans_updated = false;
|
||||
if !backtrace {
|
||||
external_spans_updated =
|
||||
self.fix_multispans_in_extern_macros(source_map, span, children);
|
||||
}
|
||||
|
||||
self.render_multispans_macro_backtrace(span, children, backtrace);
|
||||
|
||||
if !backtrace {
|
||||
if self.fix_multispans_in_extern_macros(source_map, span, children) {
|
||||
if external_spans_updated {
|
||||
let msg = format!(
|
||||
"this {} originates in a macro outside of the current crate \
|
||||
(in Nightly builds, run with -Z macro-backtrace for more info)",
|
||||
|
@ -301,42 +307,33 @@ pub trait Emitter {
|
|||
|
||||
fn render_multispans_macro_backtrace(
|
||||
&self,
|
||||
source_map: &Option<Lrc<SourceMap>>,
|
||||
span: &mut MultiSpan,
|
||||
children: &mut Vec<SubDiagnostic>,
|
||||
backtrace: bool,
|
||||
) {
|
||||
self.render_multispan_macro_backtrace(source_map, span, backtrace);
|
||||
self.render_multispan_macro_backtrace(span, backtrace);
|
||||
for child in children.iter_mut() {
|
||||
self.render_multispan_macro_backtrace(source_map, &mut child.span, backtrace);
|
||||
self.render_multispan_macro_backtrace(&mut child.span, backtrace);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_multispan_macro_backtrace(
|
||||
&self,
|
||||
source_map: &Option<Lrc<SourceMap>>,
|
||||
span: &mut MultiSpan,
|
||||
always_backtrace: bool,
|
||||
) {
|
||||
let sm = match source_map {
|
||||
Some(ref sm) => sm,
|
||||
None => return,
|
||||
};
|
||||
|
||||
fn render_multispan_macro_backtrace(&self, span: &mut MultiSpan, always_backtrace: bool) {
|
||||
let mut new_labels: Vec<(Span, String)> = vec![];
|
||||
|
||||
// First, find all the spans in <*macros> and point instead at their use site
|
||||
for &sp in span.primary_spans() {
|
||||
if sp.is_dummy() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// FIXME(eddyb) use `retain` on `macro_backtrace` to remove all the
|
||||
// entries we don't want to print, to make sure the indices being
|
||||
// printed are contiguous (or omitted if there's only one entry).
|
||||
let macro_backtrace: Vec<_> = sp.macro_backtrace().collect();
|
||||
for (i, trace) in macro_backtrace.iter().rev().enumerate() {
|
||||
// Only show macro locations that are local
|
||||
// and display them like a span_note
|
||||
if trace.def_site.is_dummy() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if always_backtrace {
|
||||
new_labels.push((
|
||||
trace.def_site,
|
||||
|
@ -353,9 +350,21 @@ pub trait Emitter {
|
|||
),
|
||||
));
|
||||
}
|
||||
// Check to make sure we're not in any <*macros>
|
||||
if !sm.span_to_filename(trace.def_site).is_macros()
|
||||
&& matches!(trace.kind, ExpnKind::Macro(MacroKind::Bang, _))
|
||||
|
||||
// Don't add a label on the call site if the diagnostic itself
|
||||
// already points to (a part of) that call site, as the label
|
||||
// is meant for showing the relevant invocation when the actual
|
||||
// diagnostic is pointing to some part of macro definition.
|
||||
//
|
||||
// This also handles the case where an external span got replaced
|
||||
// with the call site span by `fix_multispans_in_extern_macros`.
|
||||
//
|
||||
// NB: `-Zmacro-backtrace` overrides this, for uniformity, as the
|
||||
// "in this expansion of" label above is always added in that mode,
|
||||
// and it needs an "in this macro invocation" label to match that.
|
||||
let redundant_span = trace.call_site.contains(sp);
|
||||
|
||||
if !redundant_span && matches!(trace.kind, ExpnKind::Macro(MacroKind::Bang, _))
|
||||
|| always_backtrace
|
||||
{
|
||||
new_labels.push((
|
||||
|
@ -371,9 +380,9 @@ pub trait Emitter {
|
|||
},
|
||||
),
|
||||
));
|
||||
if !always_backtrace {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !always_backtrace {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -447,7 +456,7 @@ impl Emitter for EmitterWriter {
|
|||
let mut children = diag.children.clone();
|
||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
|
||||
|
||||
self.render_multispans_macro_backtrace_and_fix_extern_macros(
|
||||
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||
&self.sm,
|
||||
&mut primary_span,
|
||||
&mut children,
|
||||
|
|
|
@ -33,10 +33,7 @@ error: `$x:expr` may be followed by `=`, which is not allowed for `expr` fragmen
|
|||
--> $DIR/same-sequence-span.rs:19:1
|
||||
|
|
||||
LL | proc_macro_sequence::make_foo!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| not allowed after `expr` fragments
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not allowed after `expr` fragments
|
||||
|
|
||||
= note: allowed there are: `=>`, `,` or `;`
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@ error[E0412]: cannot find type `FromOutside` in this scope
|
|||
--> $DIR/generate-mod.rs:9:1
|
||||
|
|
||||
LL | generate_mod::check!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| not found in this scope
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
||||
|
|
||||
= note: possible candidate is found in another module, you can import it into scope:
|
||||
FromOutside
|
||||
|
@ -14,10 +11,7 @@ error[E0412]: cannot find type `Outer` in this scope
|
|||
--> $DIR/generate-mod.rs:9:1
|
||||
|
|
||||
LL | generate_mod::check!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| not found in this scope
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
||||
|
|
||||
= note: possible candidate is found in another module, you can import it into scope:
|
||||
Outer
|
||||
|
|
|
@ -2,10 +2,7 @@ error: unexpected closing delimiter: `)`
|
|||
--> $DIR/invalid-punct-ident-4.rs:6:1
|
||||
|
|
||||
LL | lexer_failure!();
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| unexpected closing delimiter
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^ unexpected closing delimiter
|
||||
|
||||
error: proc macro panicked
|
||||
--> $DIR/invalid-punct-ident-4.rs:6:1
|
||||
|
|
|
@ -2,10 +2,7 @@ error[E0425]: cannot find value `foobar2` in this scope
|
|||
--> $DIR/lints_in_proc_macros.rs:12:5
|
||||
|
|
||||
LL | bang_proc_macro2!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: a local variable with a similar name exists: `foobar`
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `foobar`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -2,19 +2,13 @@ error[E0426]: use of undeclared label `'label_use`
|
|||
--> $DIR/mixed-site-span.rs:15:9
|
||||
|
|
||||
LL | proc_macro_rules!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| undeclared label `'label_use`
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use`
|
||||
|
||||
error[E0425]: cannot find value `local_use` in this scope
|
||||
--> $DIR/mixed-site-span.rs:15:9
|
||||
|
|
||||
LL | proc_macro_rules!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| not found in this scope
|
||||
| in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
||||
|
||||
error[E0425]: cannot find value `local_def` in this scope
|
||||
--> $DIR/mixed-site-span.rs:19:9
|
||||
|
|
|
@ -2,7 +2,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:11:1
|
||||
|
|
||||
LL | subspan!("hi");
|
||||
| ^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:11:11
|
||||
|
@ -14,7 +14,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:14:1
|
||||
|
|
||||
LL | subspan!("hihi");
|
||||
| ^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:14:11
|
||||
|
@ -26,7 +26,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:17:1
|
||||
|
|
||||
LL | subspan!("hihihi");
|
||||
| ^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:17:11
|
||||
|
@ -38,7 +38,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:20:1
|
||||
|
|
||||
LL | subspan!("why I hide? hi!");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:20:17
|
||||
|
@ -50,7 +50,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:21:1
|
||||
|
|
||||
LL | subspan!("hey, hi, hidy, hidy, hi hi");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:21:16
|
||||
|
@ -62,7 +62,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:22:1
|
||||
|
|
||||
LL | subspan!("this is a hi, and this is another hi");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:22:12
|
||||
|
@ -74,7 +74,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:23:1
|
||||
|
|
||||
LL | subspan!("how are you this evening");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:23:24
|
||||
|
@ -86,7 +86,7 @@ error: found 'hi's
|
|||
--> $DIR/subspan.rs:24:1
|
||||
|
|
||||
LL | subspan!("this is highly eradic");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: here
|
||||
--> $DIR/subspan.rs:24:12
|
||||
|
|
|
@ -4,10 +4,7 @@ error[E0308]: mismatched types
|
|||
LL | / intrinsic_match! {
|
||||
LL | | "abc"
|
||||
LL | | };
|
||||
| | ^
|
||||
| | |
|
||||
| |______expected `&str`, found struct `std::string::String`
|
||||
| in this macro invocation
|
||||
| |______^ expected `&str`, found struct `std::string::String`
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue