Skip to content

Commit b997f2f

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 c92dc10 + 5b3f391 commit b997f2f

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

Lines changed: 19 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,23 @@ 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.last() {
427+
// Mark the actual macro this originates from
428+
let and_then = if let Some((macro_kind, first_name)) = has_macro_spans.first()
429+
&& first_name != name
430+
{
431+
let descr = macro_kind.descr();
432+
format!(
433+
" which{} expands to {descr} `{first_name}`",
434+
if has_macro_spans.len() > 2 { " eventually" } else { "" }
435+
)
436+
} else {
437+
"".to_string()
438+
};
427439

440+
let descr = macro_kind.descr();
428441
let msg = format!(
429-
"this {level} originates in the {descr} `{name}` \
442+
"this {level} originates in the {descr} `{name}`{and_then} \
430443
(in Nightly builds, run with -Z macro-backtrace for more info)",
431444
);
432445

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+
#![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
@@ -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

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

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

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

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

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

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 `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

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: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

0 commit comments

Comments
 (0)