Skip to content

Commit 0dd9f11

Browse files
committed
Show macro name in 'this error originates in macro' message
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
1 parent 70e52ca commit 0dd9f11

File tree

350 files changed

+744
-744
lines changed

Some content is hidden

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

350 files changed

+744
-744
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ pub trait Emitter {
309309
// are some which do actually involve macros.
310310
ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
311311

312-
ExpnKind::Macro { kind: macro_kind, name: _, proc_macro: _ } => {
313-
Some(macro_kind)
312+
ExpnKind::Macro { kind: macro_kind, name, proc_macro: _ } => {
313+
Some((macro_kind, name))
314314
}
315315
}
316316
});
@@ -322,13 +322,12 @@ pub trait Emitter {
322322
self.render_multispans_macro_backtrace(span, children, backtrace);
323323

324324
if !backtrace {
325-
if let Some(macro_kind) = has_macro_spans {
325+
if let Some((macro_kind, name)) = has_macro_spans {
326+
let descr = macro_kind.descr();
327+
326328
let msg = format!(
327-
"this {} originates in {} {} \
329+
"this {level} originates in the {descr} `{name}` \
328330
(in Nightly builds, run with -Z macro-backtrace for more info)",
329-
level,
330-
macro_kind.article(),
331-
macro_kind.descr(),
332331
);
333332

334333
children.push(SubDiagnostic {

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(crate_visibility_modifier)]
77
#![feature(backtrace)]
88
#![feature(extended_key_value_attributes)]
9+
#![feature(format_args_capture)]
910
#![feature(iter_zip)]
1011
#![feature(nll)]
1112

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
9696
^^^^
9797
= note: no item named `BarF` in scope
9898
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
99-
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
99+
= note: this warning originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)
100100

101101
warning: unresolved link to `error`
102102
--> $DIR/warning.rs:58:30

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ LL | #[derive(HashStable)]
4242
|
4343
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
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)
45+
= note: this error originates in the derive macro `HashStable` (in Nightly builds, run with -Z macro-backtrace for more info)
4646

4747
error: aborting due to 5 previous errors
4848

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +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)
24+
= note: this error originates in the macro `custom_lint_pass_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

2626
error: aborting due to 2 previous errors
2727

src/test/ui-fulldeps/session-derive-errors.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ LL | #[message = "This is missing a closing brace: {name"]
6262
| ^ expected `'}'` in format string
6363
|
6464
= note: if you intended to print `{`, you can escape it using `{{`
65-
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
65+
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
6666

6767
error: invalid format string: unmatched `}` found
6868
--> $DIR/session-derive-errors.rs:119:1
@@ -71,7 +71,7 @@ LL | #[message = "This is missing an opening brace: name}"]
7171
| ^ unmatched `}` in format string
7272
|
7373
= note: if you intended to print `}`, you can escape it using `}}`
74-
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
74+
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
7575

7676
error: The `#[label = ...]` attribute can only be applied to fields of type Span
7777
--> $DIR/session-derive-errors.rs:138:5

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | static A: usize = 0;
55
| ^^^^^^^^^^^^^^^^^^^^ the trait `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)
8+
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)
99

1010
error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
1111
--> $DIR/not-an-allocator.rs:2:1
@@ -14,7 +14,7 @@ LL | static A: usize = 0;
1414
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
1515
|
1616
= 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)
17+
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)
1818

1919
error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
2020
--> $DIR/not-an-allocator.rs:2:1
@@ -23,7 +23,7 @@ LL | static A: usize = 0;
2323
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
2424
|
2525
= 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)
26+
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)
2727

2828
error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
2929
--> $DIR/not-an-allocator.rs:2:1
@@ -32,7 +32,7 @@ LL | static A: usize = 0;
3232
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
3333
|
3434
= 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)
35+
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

3737
error: aborting due to 4 previous errors
3838

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #[global_allocator]
77
LL | static B: System = System;
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
99
|
10-
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: aborting due to previous error
1313

src/test/ui/asm/interpolated-idents.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | | pure nomem readonly preserves_flags
99
LL | | noreturn nostack att_syntax options);
1010
| |____________________________________________- in this macro invocation
1111
|
12-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
12+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
error: the `pure` and `noreturn` options are mutually exclusive
1515
--> $DIR/interpolated-idents.rs:13:13
@@ -22,7 +22,7 @@ LL | | pure nomem readonly preserves_flags
2222
LL | | noreturn nostack att_syntax options);
2323
| |____________________________________________- in this macro invocation
2424
|
25-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
25+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
2626

2727
error: asm outputs are not allowed with the `noreturn` option
2828
--> $DIR/interpolated-idents.rs:10:32
@@ -45,7 +45,7 @@ LL | | noreturn nostack att_syntax options);
4545
| |____________________________________________in this macro invocation
4646
| in this macro invocation
4747
|
48-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
48+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
4949

5050
error: aborting due to 3 previous errors
5151

src/test/ui/asm/naked-functions.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ LL | llvm_asm!("");
233233
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
234234
= note: for more information, see issue #32408 <https://github.com/rust-lang/rust/issues/32408>
235235
= help: use the new asm! syntax specified in RFC 2873
236-
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
236+
= note: this warning originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info)
237237

238238
warning: naked functions must contain a single asm block
239239
--> $DIR/naked-functions.rs:108:1

0 commit comments

Comments
 (0)