Skip to content

Commit 98a8844

Browse files
authored
Rollup merge of rust-lang#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 cdd096b + 01b2379 commit 98a8844

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

Lines changed: 18 additions & 6 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)