Skip to content

Commit 4c7eb59

Browse files
committed
rustc_macros: don't limit the -Zmacro-backtrace suggestion to extern macros.
1 parent ab08097 commit 4c7eb59

File tree

280 files changed

+888
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+888
-119
lines changed

src/librustc_errors/emitter.rs

+35-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::borrow::Cow;
2626
use std::cmp::{max, min, Reverse};
2727
use std::io;
2828
use std::io::prelude::*;
29+
use std::iter;
2930
use std::path::Path;
3031
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
3132
use termcolor::{Buffer, Color, WriteColor};
@@ -279,20 +280,41 @@ pub trait Emitter {
279280
level: &Level,
280281
backtrace: bool,
281282
) {
282-
let mut external_spans_updated = false;
283+
// Check for spans in macros, before `fix_multispans_in_extern_macros`
284+
// has a chance to replace them.
285+
let has_macro_spans = iter::once(&*span)
286+
.chain(children.iter().map(|child| &child.span))
287+
.flat_map(|span| span.primary_spans())
288+
.copied()
289+
.flat_map(|sp| {
290+
sp.macro_backtrace().filter_map(|expn_data| {
291+
match expn_data.kind {
292+
ExpnKind::Root => None,
293+
294+
// Skip past non-macro entries, just in case there
295+
// are some which do actually involve macros.
296+
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
297+
298+
ExpnKind::Macro(macro_kind, _) => Some(macro_kind),
299+
}
300+
})
301+
})
302+
.next();
303+
283304
if !backtrace {
284-
external_spans_updated =
285-
self.fix_multispans_in_extern_macros(source_map, span, children);
305+
self.fix_multispans_in_extern_macros(source_map, span, children);
286306
}
287307

288308
self.render_multispans_macro_backtrace(span, children, backtrace);
289309

290310
if !backtrace {
291-
if external_spans_updated {
311+
if let Some(macro_kind) = has_macro_spans {
292312
let msg = format!(
293-
"this {} originates in a macro outside of the current crate \
313+
"this {} originates in {} {} \
294314
(in Nightly builds, run with -Z macro-backtrace for more info)",
295315
level,
316+
macro_kind.article(),
317+
macro_kind.descr(),
296318
);
297319

298320
children.push(SubDiagnostic {
@@ -311,9 +333,8 @@ pub trait Emitter {
311333
children: &mut Vec<SubDiagnostic>,
312334
backtrace: bool,
313335
) {
314-
self.render_multispan_macro_backtrace(span, backtrace);
315-
for child in children.iter_mut() {
316-
self.render_multispan_macro_backtrace(&mut child.span, backtrace);
336+
for span in iter::once(span).chain(children.iter_mut().map(|child| &mut child.span)) {
337+
self.render_multispan_macro_backtrace(span, backtrace);
317338
}
318339
}
319340

@@ -386,6 +407,7 @@ pub trait Emitter {
386407
}
387408
}
388409
}
410+
389411
for (label_span, label_text) in new_labels {
390412
span.push_span_label(label_span, label_text);
391413
}
@@ -399,12 +421,10 @@ pub trait Emitter {
399421
source_map: &Option<Lrc<SourceMap>>,
400422
span: &mut MultiSpan,
401423
children: &mut Vec<SubDiagnostic>,
402-
) -> bool {
403-
let mut spans_updated = self.fix_multispan_in_extern_macros(source_map, span);
404-
for child in children.iter_mut() {
405-
spans_updated |= self.fix_multispan_in_extern_macros(source_map, &mut child.span);
424+
) {
425+
for span in iter::once(span).chain(children.iter_mut().map(|child| &mut child.span)) {
426+
self.fix_multispan_in_extern_macros(source_map, span);
406427
}
407-
spans_updated
408428
}
409429

410430
// This "fixes" MultiSpans that contain Spans that are pointing to locations inside of
@@ -414,10 +434,10 @@ pub trait Emitter {
414434
&self,
415435
source_map: &Option<Lrc<SourceMap>>,
416436
span: &mut MultiSpan,
417-
) -> bool {
437+
) {
418438
let sm = match source_map {
419439
Some(ref sm) => sm,
420-
None => return false,
440+
None => return,
421441
};
422442

423443
// First, find all the spans in <*macros> and point instead at their use site
@@ -438,12 +458,9 @@ pub trait Emitter {
438458
.collect();
439459

440460
// After we have them, make sure we replace these 'bad' def sites with their use sites
441-
let spans_updated = !replacements.is_empty();
442461
for (from, to) in replacements {
443462
span.replace(from, to);
444463
}
445-
446-
spans_updated
447464
}
448465
}
449466

src/test/rustdoc-ui/intra-links-warning.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,5 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
175175
bar [BarF] bar
176176
^^^^
177177
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
178+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
178179

src/test/ui-fulldeps/hash-stable-is-unstable.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ LL | #[derive(HashStable)]
4242
|
4343
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
4444
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
45+
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
4546

4647
error: aborting due to 5 previous errors
4748

src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ LL | custom_lint_pass_macro!();
2121
| -------------------------- in this macro invocation
2222
|
2323
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
24+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2425

2526
error: aborting due to 2 previous errors
2627

src/test/ui/allocator/not-an-allocator.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | static A: usize = 0;
55
| ^^^^^^^^^^^^^^^^^^^^ the trait `std::alloc::GlobalAlloc` is not implemented for `usize`
66
|
77
= note: required by `std::alloc::GlobalAlloc::alloc`
8+
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
89

910
error[E0277]: the trait bound `usize: std::alloc::GlobalAlloc` is not satisfied
1011
--> $DIR/not-an-allocator.rs:2:1
@@ -13,6 +14,7 @@ LL | static A: usize = 0;
1314
| ^^^^^^^^^^^^^^^^^^^^ the trait `std::alloc::GlobalAlloc` is not implemented for `usize`
1415
|
1516
= note: required by `std::alloc::GlobalAlloc::dealloc`
17+
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
1618

1719
error[E0277]: the trait bound `usize: std::alloc::GlobalAlloc` is not satisfied
1820
--> $DIR/not-an-allocator.rs:2:1
@@ -21,6 +23,7 @@ LL | static A: usize = 0;
2123
| ^^^^^^^^^^^^^^^^^^^^ the trait `std::alloc::GlobalAlloc` is not implemented for `usize`
2224
|
2325
= note: required by `std::alloc::GlobalAlloc::realloc`
26+
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
2427

2528
error[E0277]: the trait bound `usize: std::alloc::GlobalAlloc` is not satisfied
2629
--> $DIR/not-an-allocator.rs:2:1
@@ -29,6 +32,7 @@ LL | static A: usize = 0;
2932
| ^^^^^^^^^^^^^^^^^^^^ the trait `std::alloc::GlobalAlloc` is not implemented for `usize`
3033
|
3134
= note: required by `std::alloc::GlobalAlloc::alloc_zeroed`
35+
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
3236

3337
error: aborting due to 4 previous errors
3438

src/test/ui/allocator/two-allocators.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | static A: System = System;
66
LL | #[global_allocator]
77
LL | static B: System = System;
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
9+
|
10+
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
911

1012
error: aborting due to previous error
1113

src/test/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | x.x[0];
99
| ------ borrow later used here
1010
|
1111
= note: consider using a `let` binding to create a longer lived value
12-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
12+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
error: aborting due to previous error
1515

src/test/ui/borrowck/issue-64453.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | static settings_dir: String = format!("");
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/49146
88
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
9-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
9+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1010

1111
error: aborting due to previous error
1212

src/test/ui/borrowck/move-error-snippets.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ LL | aaa!(D);
99
...
1010
LL | sss!();
1111
| ------- in this macro invocation
12+
|
13+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1214

1315
error: aborting due to previous error
1416

src/test/ui/codemap_tests/bad-format-args.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: requires at least a format string argument
44
LL | format!();
55
| ^^^^^^^^^^
66
|
7-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: expected token: `,`
1010
--> $DIR/bad-format-args.rs:3:16

src/test/ui/codemap_tests/issue-28308.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
33
|
44
LL | assert!("foo");
55
| ^^^^^^^^^^^^^^^ cannot apply unary operator `!`
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ LL | #[cfg(feature = $expr)]
6060
...
6161
LL | generate_s10!(concat!("nonexistent"));
6262
| -------------------------------------- in this macro invocation
63+
|
64+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6365

6466
error: aborting due to 10 previous errors
6567

src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | #[cfg_attr(all(), unknown)]
66
...
77
LL | foo!();
88
| ------- in this macro invocation
9+
|
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
911

1012
error: aborting due to previous error
1113

src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | println!("{:?}", [0_usize; 33]);
66
|
77
= note: required because of the requirements on the impl of `std::fmt::Debug` for `[usize; 33]`
88
= note: required by `std::fmt::Debug::fmt`
9+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
910

1011
error[E0277]: arrays only have std trait implementations for lengths 0..=32
1112
--> $DIR/core-traits-no-impls-length-33.rs:10:16

src/test/ui/const-generics/broken-mir-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ LL | struct S<T: Debug, const N: usize>([T; N]);
1515
= note: required because of the requirements on the impl of `std::fmt::Debug` for `[T; _]`
1616
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&[T; _]`
1717
= note: required for the cast to the object type `dyn std::fmt::Debug`
18+
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
1819

1920
error: aborting due to previous error
2021

src/test/ui/const-generics/derive-debug-array-wrapper.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ LL | a: [u32; N],
1515
= note: required because of the requirements on the impl of `std::fmt::Debug` for `[u32; _]`
1616
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u32; _]`
1717
= note: required for the cast to the object type `dyn std::fmt::Debug`
18+
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
1819

1920
error: aborting due to previous error
2021

src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | assert_eq!(Y, 4);
1212
| |
1313
| referenced constant has errors
1414
|
15-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error[E0080]: evaluation of constant expression failed
1818
--> $DIR/const_fn_ptr_fail2.rs:22:5
@@ -22,7 +22,7 @@ LL | assert_eq!(Z, 4);
2222
| |
2323
| referenced constant has errors
2424
|
25-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
25+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2626

2727
error: aborting due to 2 previous errors
2828

src/test/ui/consts/const-eval/const_panic.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub const Z: () = panic!("cheese");
77
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:4:19
88
|
99
= note: `#[deny(const_err)]` on by default
10-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: any use of this value will cause an error
1313
--> $DIR/const_panic.rs:7:19
@@ -17,7 +17,7 @@ LL | pub const Y: () = unreachable!();
1717
| |
1818
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:7:19
1919
|
20-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
20+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: any use of this value will cause an error
2323
--> $DIR/const_panic.rs:10:19
@@ -27,7 +27,7 @@ LL | pub const X: () = unimplemented!();
2727
| |
2828
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:10:19
2929
|
30-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
30+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error: aborting due to 3 previous errors
3333

src/test/ui/consts/const-eval/const_panic_libcore.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | const Z: () = panic!("cheese");
77
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore.rs:5:15
88
|
99
= note: `#[deny(const_err)]` on by default
10-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: any use of this value will cause an error
1313
--> $DIR/const_panic_libcore.rs:8:15
@@ -17,7 +17,7 @@ LL | const Y: () = unreachable!();
1717
| |
1818
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore.rs:8:15
1919
|
20-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
20+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: any use of this value will cause an error
2323
--> $DIR/const_panic_libcore.rs:11:15
@@ -27,7 +27,7 @@ LL | const X: () = unimplemented!();
2727
| |
2828
| the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore.rs:11:15
2929
|
30-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
30+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error: aborting due to 3 previous errors
3333

src/test/ui/consts/const-eval/const_panic_libcore_main.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | const Z: () = panic!("cheese");
77
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:9:15
88
|
99
= note: `#[deny(const_err)]` on by default
10-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: any use of this value will cause an error
1313
--> $DIR/const_panic_libcore_main.rs:12:15
@@ -17,7 +17,7 @@ LL | const Y: () = unreachable!();
1717
| |
1818
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:12:15
1919
|
20-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
20+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: any use of this value will cause an error
2323
--> $DIR/const_panic_libcore_main.rs:15:15
@@ -27,7 +27,7 @@ LL | const X: () = unimplemented!();
2727
| |
2828
| the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore_main.rs:15:15
2929
|
30-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
30+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error: aborting due to 3 previous errors
3333

src/test/ui/consts/const-eval/feature-gate-const_panic.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | const Z: () = panic!("cheese");
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
88
= help: add `#![feature(const_panic)]` to the crate attributes to enable
9-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
9+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1010

1111
error[E0658]: panicking in constants is unstable
1212
--> $DIR/feature-gate-const_panic.rs:9:15
@@ -16,7 +16,7 @@ LL | const X: () = unimplemented!();
1616
|
1717
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
1818
= help: add `#![feature(const_panic)]` to the crate attributes to enable
19-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
19+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2020

2121
error[E0658]: panicking in constants is unstable
2222
--> $DIR/feature-gate-const_panic.rs:6:15
@@ -26,7 +26,7 @@ LL | const Y: () = unreachable!();
2626
|
2727
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
2828
= help: add `#![feature(const_panic)]` to the crate attributes to enable
29-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z macro-backtrace for more info)
29+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3030

3131
error: aborting due to 3 previous errors
3232

0 commit comments

Comments
 (0)