Skip to content

Commit

Permalink
Show macro name in 'this error originates in macro' message
Browse files Browse the repository at this point in the history
When there are multiple macros in use, it can be difficult to tell
which one was responsible for producing an error.
  • Loading branch information
Aaron1011 committed May 12, 2021
1 parent 70e52ca commit 0dd9f11
Show file tree
Hide file tree
Showing 350 changed files with 744 additions and 744 deletions.
13 changes: 6 additions & 7 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ pub trait Emitter {
// are some which do actually involve macros.
ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,

ExpnKind::Macro { kind: macro_kind, name: _, proc_macro: _ } => {
Some(macro_kind)
ExpnKind::Macro { kind: macro_kind, name, proc_macro: _ } => {
Some((macro_kind, name))
}
}
});
Expand All @@ -322,13 +322,12 @@ pub trait Emitter {
self.render_multispans_macro_backtrace(span, children, backtrace);

if !backtrace {
if let Some(macro_kind) = has_macro_spans {
if let Some((macro_kind, name)) = has_macro_spans {
let descr = macro_kind.descr();

let msg = format!(
"this {} originates in {} {} \
"this {level} originates in the {descr} `{name}` \
(in Nightly builds, run with -Z macro-backtrace for more info)",
level,
macro_kind.article(),
macro_kind.descr(),
);

children.push(SubDiagnostic {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(crate_visibility_modifier)]
#![feature(backtrace)]
#![feature(extended_key_value_attributes)]
#![feature(format_args_capture)]
#![feature(iter_zip)]
#![feature(nll)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/intra-doc/warning.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
^^^^
= note: no item named `BarF` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this warning originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unresolved link to `error`
--> $DIR/warning.rs:58:30
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/hash-stable-is-unstable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LL | #[derive(HashStable)]
|
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the derive macro `HashStable` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 5 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LL | custom_lint_pass_macro!();
| -------------------------- in this macro invocation
|
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `custom_lint_pass_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

4 changes: 2 additions & 2 deletions src/test/ui-fulldeps/session-derive-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LL | #[message = "This is missing a closing brace: {name"]
| ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: The `#[label = ...]` attribute can only be applied to fields of type Span
--> $DIR/session-derive-errors.rs:138:5
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/allocator/not-an-allocator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | static A: usize = 0;
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= note: required by `std::alloc::GlobalAlloc::alloc`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
--> $DIR/not-an-allocator.rs:2:1
Expand All @@ -14,7 +14,7 @@ LL | static A: usize = 0;
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= note: required by `std::alloc::GlobalAlloc::dealloc`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
--> $DIR/not-an-allocator.rs:2:1
Expand All @@ -23,7 +23,7 @@ LL | static A: usize = 0;
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= note: required by `std::alloc::GlobalAlloc::realloc`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
--> $DIR/not-an-allocator.rs:2:1
Expand All @@ -32,7 +32,7 @@ LL | static A: usize = 0;
| ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= note: required by `std::alloc::GlobalAlloc::alloc_zeroed`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/allocator/two-allocators.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | #[global_allocator]
LL | static B: System = System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

6 changes: 3 additions & 3 deletions src/test/ui/asm/interpolated-idents.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | | pure nomem readonly preserves_flags
LL | | noreturn nostack att_syntax options);
| |____________________________________________- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

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

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

error: aborting due to 3 previous errors

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

warning: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:108:1
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/asm/parse-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ error: asm template must be a string literal
LL | asm!(format!("{{{}}}", 0), in(reg) foo);
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:37:37
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/type-check-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LL | asm!("{}", in(reg) vec![0]);
| ^^^^^^^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot use value of type `(i32, i32, i32)` for inline assembly
--> $DIR/type-check-2.rs:70:28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-73541-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | b!();
| ----- in this macro invocation
|
= note: labels are unreachable through functions, closures, async blocks and modules
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/attributes/key-value-expansion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LL | bug!("bug" + stringify!(found));
LL | bug!();
| ------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `bug` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: aborting due to 3 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/attributes/nonterminal-expansion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | #[repr(align($n))]
LL | pass_nonterminal!(n!());
| ------------------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/binop/issue-77910-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | assert_eq!(foo, y);
| for<'r> fn(&'r i32) -> &'r i32 {foo}
| _
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | x.x[0];
| ------ borrow later used here
|
= note: consider using a `let` binding to create a longer lived value
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/issue-25793.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | r.get_size(width!(self))
| |
| borrow later used by call
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `width` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/borrowck/issue-64453.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ error[E0015]: calls in statics are limited to constant functions, tuple structs
LL | static settings_dir: String = format!("");
| ^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/move-error-snippets.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LL | let a = $c;
LL | sss!();
| ------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `aaa` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/bound-suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | println!("{:?}", t);
| ^ `impl Sized` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
|
LL | fn test_impl(t: impl Sized + std::fmt::Debug) {
Expand All @@ -18,7 +18,7 @@ LL | println!("{:?}", t);
| ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
|
LL | fn test_no_bounds<T: std::fmt::Debug>(t: T) {
Expand All @@ -31,7 +31,7 @@ LL | println!("{:?}", t);
| ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
|
LL | fn test_one_bound<T: Sized + std::fmt::Debug>(t: T) {
Expand All @@ -44,7 +44,7 @@ LL | println!("{:?} {:?}", x, y);
| ^ `Y` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `Y`
|
LL | fn test_no_bounds_where<X, Y>(x: X, y: Y) where X: std::fmt::Debug, Y: std::fmt::Debug {
Expand All @@ -57,7 +57,7 @@ LL | println!("{:?}", x);
| ^ `X` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
|
LL | fn test_one_bound_where<X>(x: X) where X: Sized + std::fmt::Debug {
Expand All @@ -70,7 +70,7 @@ LL | println!("{:?}", x);
| ^ `X` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `X`
|
LL | fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized, X: std::fmt::Debug {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/bad-format-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: requires at least a format string argument
LL | format!();
| ^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `,`, found `1`
--> $DIR/bad-format-args.rs:3:16
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/issue-28308.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
LL | assert!("foo");
| ^^^^^^^^^^^^^^^ cannot apply unary operator `!`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Expand Down
Loading

0 comments on commit 0dd9f11

Please sign in to comment.