Skip to content

Commit 9daf546

Browse files
committed
Auto merge of #82069 - Aaron1011:verbose-in-macro, r=estebank
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.
2 parents 31bd868 + 0dd9f11 commit 9daf546

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

+6-7
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

+1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+4-4
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

+1-1
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

+3-3
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

+1-1
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

src/test/ui/asm/parse-error.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ error: asm template must be a string literal
154154
LL | asm!(format!("{{{}}}", 0), in(reg) foo);
155155
| ^^^^^^^^^^^^^^^^^^^^
156156
|
157-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
157+
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
158158

159159
error: asm template must be a string literal
160160
--> $DIR/parse-error.rs:62:21
161161
|
162162
LL | asm!("{1}", format!("{{{}}}", 0), in(reg) foo, out(reg) bar);
163163
| ^^^^^^^^^^^^^^^^^^^^
164164
|
165-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
165+
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
166166

167167
error[E0435]: attempt to use a non-constant value in a constant
168168
--> $DIR/parse-error.rs:37:37

src/test/ui/asm/type-check-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LL | asm!("{}", in(reg) vec![0]);
2727
| ^^^^^^^
2828
|
2929
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
30-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
30+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error: cannot use value of type `(i32, i32, i32)` for inline assembly
3333
--> $DIR/type-check-2.rs:70:28

src/test/ui/associated-consts/defaults-not-assumed-fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
2424
|
2525
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2626
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
27-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
27+
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2828

2929
error: aborting due to 3 previous errors
3030

src/test/ui/async-await/issue-73541-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | b!();
1111
| ----- in this macro invocation
1212
|
1313
= note: labels are unreachable through functions, closures, async blocks and modules
14-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
14+
= note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
1515

1616
error: aborting due to previous error
1717

src/test/ui/attributes/key-value-expansion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | bug!("bug" + stringify!(found));
1313
LL | bug!();
1414
| ------- in this macro invocation
1515
|
16-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
16+
= note: this error originates in the macro `bug` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

1818
error: unexpected token: `{
1919
let res =
@@ -33,7 +33,7 @@ LL | doc_comment! {format!("{coor}", coor = stringify!($t1)).as_str()}
3333
LL | some_macro!(u8);
3434
| ---------------- in this macro invocation
3535
|
36-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
36+
= note: this error originates in the macro `some_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
3737

3838
error: aborting due to 3 previous errors
3939

src/test/ui/attributes/nonterminal-expansion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #[repr(align($n))]
77
LL | pass_nonterminal!(n!());
88
| ------------------------ in this macro invocation
99
|
10-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: aborting due to previous error
1313

src/test/ui/binop/issue-77910-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | assert_eq!(foo, y);
77
| for<'r> fn(&'r i32) -> &'r i32 {foo}
88
| _
99
|
10-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error[E0277]: `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
1313
--> $DIR/issue-77910-1.rs:8:5
@@ -21,7 +21,7 @@ LL | T: fmt::Debug + ?Sized,
2121
| ---------- required by this bound in `core::panicking::assert_failed`
2222
|
2323
= help: the trait `Debug` is not implemented for `for<'r> fn(&'r i32) -> &'r i32 {foo}`
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 `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

2626
error: aborting due to 2 previous errors
2727

src/test/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | x.x[0];
99
| ------ borrow later used here
1010
|
1111
= note: consider using a `let` binding to create a longer lived value
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 `vec` (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-25793.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | r.get_size(width!(self))
1111
| |
1212
| borrow later used by call
1313
|
14-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
14+
= note: this error originates in the macro `width` (in Nightly builds, run with -Z macro-backtrace for more info)
1515

1616
error: aborting due to previous error
1717

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ error[E0015]: calls in statics are limited to constant functions, tuple structs
1010
LL | static settings_dir: String = format!("");
1111
| ^^^^^^^^^^^
1212
|
13-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
13+
= note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
1616
--> $DIR/issue-64453.rs:4:31
1717
|
1818
LL | static settings_dir: String = format!("");
1919
| ^^^^^^^^^^^
2020
|
21-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
21+
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
2222

2323
error: aborting due to 3 previous errors
2424

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 a macro (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in the 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/bound-suggestions.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | println!("{:?}", t);
55
| ^ `impl Sized` cannot be formatted using `{:?}` because it doesn't implement `Debug`
66
|
77
= note: required by `std::fmt::Debug::fmt`
8-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
99
help: consider further restricting this bound
1010
|
1111
LL | fn test_impl(t: impl Sized + std::fmt::Debug) {
@@ -18,7 +18,7 @@ LL | println!("{:?}", t);
1818
| ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
1919
|
2020
= note: required by `std::fmt::Debug::fmt`
21-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
21+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
2222
help: consider restricting type parameter `T`
2323
|
2424
LL | fn test_no_bounds<T: std::fmt::Debug>(t: T) {
@@ -31,7 +31,7 @@ LL | println!("{:?}", t);
3131
| ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
3232
|
3333
= note: required by `std::fmt::Debug::fmt`
34-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
34+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
3535
help: consider further restricting this bound
3636
|
3737
LL | fn test_one_bound<T: Sized + std::fmt::Debug>(t: T) {
@@ -44,7 +44,7 @@ LL | println!("{:?} {:?}", x, y);
4444
| ^ `Y` cannot be formatted using `{:?}` because it doesn't implement `Debug`
4545
|
4646
= note: required by `std::fmt::Debug::fmt`
47-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
47+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
4848
help: consider further restricting type parameter `Y`
4949
|
5050
LL | fn test_no_bounds_where<X, Y>(x: X, y: Y) where X: std::fmt::Debug, Y: std::fmt::Debug {
@@ -57,7 +57,7 @@ LL | println!("{:?}", x);
5757
| ^ `X` cannot be formatted using `{:?}` because it doesn't implement `Debug`
5858
|
5959
= note: required by `std::fmt::Debug::fmt`
60-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
60+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
6161
help: consider further restricting this bound
6262
|
6363
LL | fn test_one_bound_where<X>(x: X) where X: Sized + std::fmt::Debug {
@@ -70,7 +70,7 @@ LL | println!("{:?}", x);
7070
| ^ `X` cannot be formatted using `{:?}` because it doesn't implement `Debug`
7171
|
7272
= note: required by `std::fmt::Debug::fmt`
73-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
73+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
7474
help: consider further restricting type parameter `X`
7575
|
7676
LL | fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized, X: std::fmt::Debug {

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 a macro (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the 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/issue-28308.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
44
LL | assert!("foo");
55
| ^^^^^^^^^^^^^^^ cannot apply unary operator `!`
66
|
7-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)