Skip to content

Commit 5b3f391

Browse files
Mention first and last macro in backtrace
1 parent 8308806 commit 5b3f391

File tree

75 files changed

+152
-138
lines changed

Some content is hidden

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

75 files changed

+152
-138
lines changed

compiler/rustc_errors/src/emitter.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ pub trait Emitter {
389389
) {
390390
// Check for spans in macros, before `fix_multispans_in_extern_macros`
391391
// has a chance to replace them.
392-
let has_macro_spans = iter::once(&*span)
392+
let has_macro_spans: Vec<_> = iter::once(&*span)
393393
.chain(children.iter().map(|child| &child.span))
394394
.flat_map(|span| span.primary_spans())
395395
.flat_map(|sp| sp.macro_backtrace())
396-
.find_map(|expn_data| {
396+
.filter_map(|expn_data| {
397397
match expn_data.kind {
398398
ExpnKind::Root => None,
399399

@@ -403,7 +403,8 @@ pub trait Emitter {
403403

404404
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
405405
}
406-
});
406+
})
407+
.collect();
407408

408409
if !backtrace {
409410
self.fix_multispans_in_extern_macros(source_map, span, children);
@@ -412,11 +413,23 @@ pub trait Emitter {
412413
self.render_multispans_macro_backtrace(span, children, backtrace);
413414

414415
if !backtrace {
415-
if let Some((macro_kind, name)) = has_macro_spans {
416-
let descr = macro_kind.descr();
416+
if let Some((macro_kind, name)) = has_macro_spans.last() {
417+
// Mark the actual macro this originates from
418+
let and_then = if let Some((macro_kind, first_name)) = has_macro_spans.first()
419+
&& first_name != name
420+
{
421+
let descr = macro_kind.descr();
422+
format!(
423+
" which{} expands to {descr} `{first_name}`",
424+
if has_macro_spans.len() > 2 { " eventually" } else { "" }
425+
)
426+
} else {
427+
"".to_string()
428+
};
417429

430+
let descr = macro_kind.descr();
418431
let msg = format!(
419-
"this {level} originates in the {descr} `{name}` \
432+
"this {level} originates in the {descr} `{name}`{and_then} \
420433
(in Nightly builds, run with -Z macro-backtrace for more info)",
421434
);
422435

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(drain_filter)]
77
#![feature(backtrace)]
88
#![feature(if_let_guard)]
9+
#![feature(let_chains)]
910
#![feature(let_else)]
1011
#![feature(never_type)]
1112
#![feature(adt_const_params)]

src/test/ui/borrowck/borrowck-and-init.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0381]: borrow of possibly-uninitialized variable: `i`
44
LL | println!("{}", i);
55
| ^ use of possibly-uninitialized `i`
66
|
7-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/borrowck/borrowck-break-uninit-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
44
LL | println!("{}", x);
55
| ^ use of possibly-uninitialized `x`
66
|
7-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/borrowck/borrowck-break-uninit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
44
LL | println!("{}", x);
55
| ^ use of possibly-uninitialized `x`
66
|
7-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/borrowck/borrowck-or-init.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0381]: borrow of possibly-uninitialized variable: `i`
44
LL | println!("{}", i);
55
| ^ use of possibly-uninitialized `i`
66
|
7-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/borrowck/borrowck-while-break.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0381]: borrow of possibly-uninitialized variable: `v`
44
LL | println!("{}", v);
55
| ^ use of possibly-uninitialized `v`
66
|
7-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/borrowck/issue-24267-flow-exit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
44
LL | println!("{}", x);
55
| ^ use of possibly-uninitialized `x`
66
|
7-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error[E0381]: borrow of possibly-uninitialized variable: `x`
1010
--> $DIR/issue-24267-flow-exit.rs:18:20
1111
|
1212
LL | println!("{}", x);
1313
| ^ use of possibly-uninitialized `x`
1414
|
15-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error: aborting due to 2 previous errors
1818

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | static settings_dir: String = format!("");
55
| ^^^^^^^^^^^
66
|
77
= help: add `#![feature(const_fmt_arguments_new)]` to the crate attributes to enable
8-
= note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
= note: this error originates in the macro `format` which expands to macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
99

1010
error[E0015]: cannot call non-const fn `format` in statics
1111
--> $DIR/issue-64453.rs:4:31

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | panic!()
1010
| the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:12:5
1111
| inside `f::<[closure@$DIR/issue-81899.rs:4:31: 4:37]>` at $SRC_DIR/std/src/panic.rs:LL:COL
1212
|
13-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
= note: this error originates in the macro `panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error: any use of this value will cause an error
1616
--> $DIR/issue-81899.rs:4:23

src/test/ui/borrowck/issue-88434-minimal-example.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | panic!()
1010
| the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:11:5
1111
| inside `f::<[closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:31]>` at $SRC_DIR/std/src/panic.rs:LL:COL
1212
|
13-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
= note: this error originates in the macro `panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error: any use of this value will cause an error
1616
--> $DIR/issue-88434-minimal-example.rs:3:21

src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | panic!()
1010
| the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:11:5
1111
| inside `f::<[closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:37]>` at $SRC_DIR/std/src/panic.rs:LL:COL
1212
|
13-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
= note: this error originates in the macro `panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error: any use of this value will cause an error
1616
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:23

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | let a = $c;
1212
LL | sss!();
1313
| ------ in this macro invocation
1414
|
15-
= note: this error originates in the macro `aaa` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in the macro `sss` which expands to macro `aaa` (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error: aborting due to previous error
1818

src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ LL | println!("{}", arr[3]);
8282
LL | c();
8383
| - mutable borrow later used here
8484
|
85-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
85+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
8686

8787
error[E0502]: cannot borrow `arr` as immutable because it is also borrowed as mutable
8888
--> $DIR/arrays.rs:73:24

src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LL |
2626
LL | c();
2727
| - mutable borrow later used here
2828
|
29-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
29+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
3030

3131
error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed
3232
--> $DIR/box.rs:55:5

src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | println!("{}", foo.x);
99
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
1010
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
1111
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
12-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
error: aborting due to previous error
1515

@@ -25,5 +25,5 @@ LL | println!("{}", foo.x);
2525
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
2626
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
2727
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
28-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
28+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
2929

src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL |
1414
LL | c();
1515
| - mutable borrow later used here
1616
|
17-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
17+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1818

1919
error: aborting due to previous error
2020

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 the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `format` which expands to macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
88

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

src/test/ui/codemap_tests/tab_3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ note: this function takes ownership of the receiver `self`, which moves `some_ve
1414
|
1515
LL | fn into_iter(self) -> Self::IntoIter;
1616
| ^^^^
17-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
17+
= note: this error originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1818

1919
error: aborting due to previous error
2020

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ LL | println!("{}", FOO);
2828
|
2929
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3030
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
31-
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
31+
= note: this warning originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
3232

3333
error: aborting due to previous error; 2 warnings emitted
3434

@@ -64,5 +64,5 @@ LL | #![warn(const_err)]
6464
| ^^^^^^^^^
6565
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6666
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
67-
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
67+
= note: this warning originates in the macro `println` which expands to macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
6868

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ error[E0080]: evaluation of constant value failed
44
LL | const Z: () = std::panic!("cheese");
55
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:6:15
66
|
7-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `std::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error[E0080]: evaluation of constant value failed
1010
--> $DIR/const_panic.rs:9:16
1111
|
1212
LL | const Z2: () = std::panic!();
1313
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:9:16
1414
|
15-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in the macro `std::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error[E0080]: evaluation of constant value failed
1818
--> $DIR/const_panic.rs:12:15
1919
|
2020
LL | const Y: () = std::unreachable!();
2121
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:12:15
2222
|
23-
= note: this error originates in the macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
23+
= note: this error originates in the macro `std::unreachable` which expands to macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
2424

2525
error[E0080]: evaluation of constant value failed
2626
--> $DIR/const_panic.rs:15:15
@@ -36,39 +36,39 @@ error[E0080]: evaluation of constant value failed
3636
LL | const W: () = std::panic!(MSG);
3737
| ^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:18:15
3838
|
39-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
39+
= note: this error originates in the macro `std::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
4040

4141
error[E0080]: evaluation of constant value failed
4242
--> $DIR/const_panic.rs:21:16
4343
|
4444
LL | const W2: () = std::panic!("{}", MSG);
4545
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:21:16
4646
|
47-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
47+
= note: this error originates in the macro `std::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
4848

4949
error[E0080]: evaluation of constant value failed
5050
--> $DIR/const_panic.rs:24:20
5151
|
5252
LL | const Z_CORE: () = core::panic!("cheese");
5353
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:24:20
5454
|
55-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
55+
= note: this error originates in the macro `core::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
5656

5757
error[E0080]: evaluation of constant value failed
5858
--> $DIR/const_panic.rs:27:21
5959
|
6060
LL | const Z2_CORE: () = core::panic!();
6161
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:27:21
6262
|
63-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
63+
= note: this error originates in the macro `core::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
6464

6565
error[E0080]: evaluation of constant value failed
6666
--> $DIR/const_panic.rs:30:20
6767
|
6868
LL | const Y_CORE: () = core::unreachable!();
6969
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:30:20
7070
|
71-
= note: this error originates in the macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
71+
= note: this error originates in the macro `core::unreachable` which expands to macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
7272

7373
error[E0080]: evaluation of constant value failed
7474
--> $DIR/const_panic.rs:33:20
@@ -84,15 +84,15 @@ error[E0080]: evaluation of constant value failed
8484
LL | const W_CORE: () = core::panic!(MSG);
8585
| ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:36:20
8686
|
87-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
87+
= note: this error originates in the macro `core::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
8888

8989
error[E0080]: evaluation of constant value failed
9090
--> $DIR/const_panic.rs:39:21
9191
|
9292
LL | const W2_CORE: () = core::panic!("{}", MSG);
9393
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:39:21
9494
|
95-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
95+
= note: this error originates in the macro `core::panic` which expands to macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
9696

9797
error: aborting due to 12 previous errors
9898

0 commit comments

Comments
 (0)