Skip to content

Commit af13e55

Browse files
authored
Rollup merge of #98320 - compiler-errors:macro-backtrace, r=estebank
Mention first and last macro in backtrace Slight improvement to diagnostic mentioning what macro an error originates from. Not sure if it's worthwhile.
2 parents 881e1c1 + 01b2379 commit af13e55

File tree

78 files changed

+157
-144
lines changed

Some content is hidden

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

78 files changed

+157
-144
lines changed

compiler/rustc_errors/src/emitter.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ pub trait Emitter {
399399
) {
400400
// Check for spans in macros, before `fix_multispans_in_extern_macros`
401401
// has a chance to replace them.
402-
let has_macro_spans = iter::once(&*span)
402+
let has_macro_spans: Vec<_> = iter::once(&*span)
403403
.chain(children.iter().map(|child| &child.span))
404404
.flat_map(|span| span.primary_spans())
405405
.flat_map(|sp| sp.macro_backtrace())
406-
.find_map(|expn_data| {
406+
.filter_map(|expn_data| {
407407
match expn_data.kind {
408408
ExpnKind::Root => None,
409409

@@ -413,7 +413,8 @@ pub trait Emitter {
413413

414414
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
415415
}
416-
});
416+
})
417+
.collect();
417418

418419
if !backtrace {
419420
self.fix_multispans_in_extern_macros(source_map, span, children);
@@ -422,11 +423,22 @@ pub trait Emitter {
422423
self.render_multispans_macro_backtrace(span, children, backtrace);
423424

424425
if !backtrace {
425-
if let Some((macro_kind, name)) = has_macro_spans {
426-
let descr = macro_kind.descr();
426+
if let Some((macro_kind, name)) = has_macro_spans.first() {
427+
// Mark the actual macro this originates from
428+
let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
429+
&& last_name != name
430+
{
431+
let descr = macro_kind.descr();
432+
format!(
433+
" which comes from the expansion of the {descr} `{last_name}`",
434+
)
435+
} else {
436+
"".to_string()
437+
};
427438

439+
let descr = macro_kind.descr();
428440
let msg = format!(
429-
"this {level} originates in the {descr} `{name}` \
441+
"this {level} originates in the {descr} `{name}`{and_then} \
430442
(in Nightly builds, run with -Z macro-backtrace for more info)",
431443
);
432444

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+
#![cfg_attr(bootstrap, 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
@@ -9,7 +9,7 @@ LL | println!("{}", false && { i = 5; true });
99
LL | println!("{}", i);
1010
| ^ `i` used here but it is possibly-uninitialized
1111
|
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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
error: aborting due to previous error
1515

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let x: isize;
77
LL | println!("{}", x);
88
| ^ `x` used here but it isn't initialized
99
|
10-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: aborting due to previous error
1313

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let x: isize;
77
LL | println!("{}", x);
88
| ^ `x` used here but it isn't initialized
99
|
10-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: aborting due to previous error
1313

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | println!("{}", false || { i = 5; true });
99
LL | println!("{}", i);
1010
| ^ `i` used here but it is possibly-uninitialized
1111
|
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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
error: aborting due to previous error
1515

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | while cond {
99
LL | println!("{}", v);
1010
| ^ `v` used here but it is possibly-uninitialized
1111
|
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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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-24267-flow-exit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | loop { x = break; }
77
LL | println!("{}", x);
88
| ^ `x` used here but it isn't initialized
99
|
10-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error[E0381]: used binding `x` isn't initialized
1313
--> $DIR/issue-24267-flow-exit.rs:18:20
@@ -18,7 +18,7 @@ LL | for _ in 0..10 { x = continue; }
1818
LL | println!("{}", x);
1919
| ^ `x` used here but it isn't initialized
2020
|
21-
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
21+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
2222

2323
error: aborting due to 2 previous errors
2424

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 `$crate::__export::format_args` which comes from the expansion of the macro `format` (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:34]>` 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 `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (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:28]>` 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 `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (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:34]>` 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 `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (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 `aaa` which comes from the expansion of the macro `sss` (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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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 `$crate::__export::format_args` which comes from the expansion of the macro `format` (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 `$crate::format_args_nl` which comes from the expansion of the macro `println` (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
@@ -26,7 +26,7 @@ LL | println!("{}", FOO);
2626
|
2727
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2828
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
29-
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
29+
= note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
3030

3131
error: aborting due to previous error; 2 warnings emitted
3232

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

0 commit comments

Comments
 (0)