Skip to content

Do not suggest using -Zmacro-backtrace for builtin macros #138379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
@@ -297,7 +297,9 @@ pub trait Emitter: Translate {
// are some which do actually involve macros.
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,

ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
ExpnKind::Macro(macro_kind, name) => {
Some((macro_kind, name, expn_data.hide_backtrace))
}
}
})
.collect();
@@ -309,13 +311,17 @@ pub trait Emitter: Translate {
self.render_multispans_macro_backtrace(span, children, backtrace);

if !backtrace {
if let Some((macro_kind, name)) = has_macro_spans.first() {
// Skip builtin macros, as their expansion isn't relevant to the end user. This includes
// actual intrinsics, like `asm!`.
if let Some((macro_kind, name, _)) = has_macro_spans.first()
&& let Some((_, _, false)) = has_macro_spans.last()
{
// Mark the actual macro this originates from
let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
let and_then = if let Some((macro_kind, last_name, _)) = has_macro_spans.last()
&& last_name != name
{
let descr = macro_kind.descr();
format!(" which comes from the expansion of the {descr} `{last_name}`",)
format!(" which comes from the expansion of the {descr} `{last_name}`")
} else {
"".to_string()
};
12 changes: 8 additions & 4 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
@@ -889,16 +889,16 @@ impl SyntaxExtension {
})
.unwrap_or_else(|| (None, helper_attrs));

let stability = find_attr!(attrs, AttributeKind::Stability{stability, ..} => *stability);
let stability = find_attr!(attrs, AttributeKind::Stability { stability, .. } => *stability);

// FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem
if let Some(sp) = find_attr!(attrs, AttributeKind::ConstStability{span, ..} => *span) {
if let Some(sp) = find_attr!(attrs, AttributeKind::ConstStability { span, .. } => *span) {
sess.dcx().emit_err(errors::MacroConstStability {
span: sp,
head_span: sess.source_map().guess_head_span(span),
});
}
if let Some(sp) = find_attr!(attrs, AttributeKind::BodyStability{span, ..} => *span) {
if let Some(sp) = find_attr!(attrs, AttributeKind::BodyStability{ span, .. } => *span) {
sess.dcx().emit_err(errors::MacroBodyStability {
span: sp,
head_span: sess.source_map().guess_head_span(span),
@@ -912,7 +912,10 @@ impl SyntaxExtension {
// FIXME(jdonszelmann): avoid the into_iter/collect?
.then(|| allow_internal_unstable.iter().map(|i| i.0).collect::<Vec<_>>().into()),
stability,
deprecation: find_attr!(attrs, AttributeKind::Deprecation{deprecation, ..} => *deprecation),
deprecation: find_attr!(
attrs,
AttributeKind::Deprecation { deprecation, .. } => *deprecation
),
helper_attrs,
edition,
builtin_name,
@@ -1000,6 +1003,7 @@ impl SyntaxExtension {
self.allow_internal_unsafe,
self.local_inner_macros,
self.collapse_debuginfo,
self.builtin_name.is_some(),
)
}
}
5 changes: 5 additions & 0 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
@@ -982,6 +982,8 @@ pub struct ExpnData {
/// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
/// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
pub(crate) collapse_debuginfo: bool,
/// When true, we do not display the note telling people to use the `-Zmacro-backtrace` flag.
pub hide_backtrace: bool,
}

impl !PartialEq for ExpnData {}
@@ -1000,6 +1002,7 @@ impl ExpnData {
allow_internal_unsafe: bool,
local_inner_macros: bool,
collapse_debuginfo: bool,
hide_backtrace: bool,
) -> ExpnData {
ExpnData {
kind,
@@ -1014,6 +1017,7 @@ impl ExpnData {
allow_internal_unsafe,
local_inner_macros,
collapse_debuginfo,
hide_backtrace,
}
}

@@ -1038,6 +1042,7 @@ impl ExpnData {
allow_internal_unsafe: false,
local_inner_macros: false,
collapse_debuginfo: false,
hide_backtrace: false,
}
}

4 changes: 0 additions & 4 deletions src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ LL | impl PartialOrd for DeriveOrd {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::derive_ord_xor_partial_ord)]`
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)

error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
--> tests/ui/derive_ord_xor_partial_ord.rs:33:10
@@ -24,7 +23,6 @@ note: `PartialOrd` implemented here
|
LL | impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)

error: you are implementing `Ord` explicitly but have derived `PartialOrd`
--> tests/ui/derive_ord_xor_partial_ord.rs:47:1
@@ -42,7 +40,6 @@ note: `PartialOrd` implemented here
|
LL | #[derive(PartialOrd, PartialEq, Eq)]
| ^^^^^^^^^^
= note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)

error: you are implementing `Ord` explicitly but have derived `PartialOrd`
--> tests/ui/derive_ord_xor_partial_ord.rs:69:5
@@ -60,7 +57,6 @@ note: `PartialOrd` implemented here
|
LL | #[derive(PartialOrd, PartialEq, Eq)]
| ^^^^^^^^^^
= note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors

2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ note: `PartialEq` implemented here
LL | impl PartialEq for Bar {
| ^^^^^^^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::derived_hash_with_manual_eq)]` on by default
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)

error: you are deriving `Hash` but have implemented `PartialEq` explicitly
--> tests/ui/derived_hash_with_manual_eq.rs:23:10
@@ -23,7 +22,6 @@ note: `PartialEq` implemented here
|
LL | impl PartialEq<Baz> for Baz {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/diverging_sub_expression.stderr
Original file line number Diff line number Diff line change
@@ -36,8 +36,6 @@ error: sub-expression diverges
|
LL | _ => true || panic!("boo"),
| ^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error: sub-expression diverges
--> tests/ui/diverging_sub_expression.rs:52:29
3 changes: 0 additions & 3 deletions src/tools/clippy/tests/ui/fallible_impl_from.stderr
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ note: potential failure(s)
|
LL | panic!();
| ^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error: consider implementing `TryFrom` instead
--> tests/ui/fallible_impl_from.rs:40:1
@@ -64,7 +63,6 @@ LL | } else if s.parse::<u32>().unwrap() != 42 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL | panic!("{:?}", s);
| ^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error: consider implementing `TryFrom` instead
--> tests/ui/fallible_impl_from.rs:60:1
@@ -85,7 +83,6 @@ LL | if s.parse::<u32>().ok().unwrap() != 42 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | panic!("{:?}", s);
| ^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors

Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ LL | #[derive(Hash)]
= note: ... as (`hash("abc") != hash("abc".as_bytes())`
= help: consider either removing one of the `Borrow` implementations (`Borrow<str>` or `Borrow<[u8]>`) ...
= help: ... or not implementing `Hash` for this type
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the semantics of `Borrow<T>` around `Hash` can't be satisfied when both `Borrow<str>` and `Borrow<[u8]>` are implemented
--> tests/ui/impl_hash_with_borrow_str_and_bytes.rs:117:6
3 changes: 0 additions & 3 deletions src/tools/clippy/tests/ui/issue-7447.stderr
Original file line number Diff line number Diff line change
@@ -6,15 +6,12 @@ LL | byte_view(panic!());
|
= note: `-D clippy::diverging-sub-expression` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]`
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error: sub-expression diverges
--> tests/ui/issue-7447.rs:29:19
|
LL | group_entries(panic!());
| ^^^^^^^^
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/same_name_method.stderr
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ note: existing `clone` defined here
|
LL | #[derive(Clone)]
| ^^^^^
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error: method's name is the same as an existing method in a trait
--> tests/ui/same_name_method.rs:46:13
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ note: inside `miri_start`
|
LL | handle_alloc_error(Layout::for_value(&0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

2 changes: 0 additions & 2 deletions src/tools/miri/tests/fail/erroneous_const.stderr
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@ error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
|
LL | const VOID: ! = panic!();
| ^^^^^^^^ evaluation panicked: explicit panic
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
--> tests/fail/erroneous_const.rs:LL:CC
1 change: 0 additions & 1 deletion src/tools/miri/tests/fail/panic/no_std.stderr
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ note: inside `miri_start`
|
LL | panic!("blarg I am dead")
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

1 change: 0 additions & 1 deletion src/tools/miri/tests/fail/panic/panic_abort1.stderr
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ note: inside `main`
|
LL | std::panic!("panicking from libstd");
| ^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

1 change: 0 additions & 1 deletion src/tools/miri/tests/fail/panic/panic_abort2.stderr
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ note: inside `main`
|
LL | std::panic!("{}-panicking from libstd", 42);
| ^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

1 change: 0 additions & 1 deletion src/tools/miri/tests/fail/panic/panic_abort3.stderr
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ note: inside `main`
|
LL | core::panic!("panicking from libcore");
| ^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

1 change: 0 additions & 1 deletion src/tools/miri/tests/fail/panic/panic_abort4.stderr
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ note: inside `main`
|
LL | core::panic!("{}-panicking from libcore", 42);
| ^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

4 changes: 0 additions & 4 deletions tests/run-make/non-unicode-env/non_unicode_env.stderr
Original file line number Diff line number Diff line change
@@ -3,16 +3,12 @@ error: environment variable `NON_UNICODE_VAR` is not a valid Unicode string
|
2 | let _ = env!("NON_UNICODE_VAR");
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)

error: environment variable `NON_UNICODE_VAR` is not a valid Unicode string
--> non_unicode_env.rs:3:13
|
3 | let _ = option_env!("NON_UNICODE_VAR");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `option_env` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@ error: couldn't read `$DIR/relative-dir-empty-file`: $FILE_NOT_FOUND_MSG (os err
|
LL | let x = include_bytes!("relative-dir-empty-file");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ LL | fn oom(
| ^^^
LL | info: &Layout,
| -------------
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/alloc-error-handler-bad-signature-1.rs:10:1
@@ -35,7 +34,6 @@ LL | | }
|
= note: expected type `!`
found unit type `()`
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ LL | fn oom(
| ^^^
LL | info: Layout,
| ------------
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/alloc-error-handler-bad-signature-2.rs:10:1
@@ -43,7 +42,6 @@ LL | | }
|
= note: expected type `!`
found unit type `()`
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ note: function defined here
|
LL | fn oom() -> ! {
| ^^^
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

4 changes: 0 additions & 4 deletions tests/ui/allocator/not-an-allocator.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ LL | static A: usize = 0;
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= help: the trait `GlobalAlloc` is implemented for `System`
= 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:11
@@ -19,7 +18,6 @@ LL | static A: usize = 0;
|
= help: the trait `GlobalAlloc` is implemented for `System`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= 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:11
@@ -31,7 +29,6 @@ LL | static A: usize = 0;
|
= help: the trait `GlobalAlloc` is implemented for `System`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= 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:11
@@ -43,7 +40,6 @@ LL | static A: usize = 0;
|
= help: the trait `GlobalAlloc` is implemented for `System`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= 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

2 changes: 0 additions & 2 deletions tests/ui/allocator/two-allocators.stderr
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ LL | #[global_allocator]
| ------------------- in this procedural macro expansion
LL | static B: System = System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
|
= 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 1 previous error

2 changes: 0 additions & 2 deletions tests/ui/asm/ice-bad-err-span-in-template-129503.stderr
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ LL | asm!(concat!(r#"lJ𐏿Æ�.𐏿�"#, "r} {}"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unmatched `}` in asm template string
|
= note: if you intended to print `}`, you can escape it using `}}`
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)

error: invalid asm template string: unmatched `}` found
--> $DIR/ice-bad-err-span-in-template-129503.rs:18:10
@@ -14,7 +13,6 @@ LL | asm!(concat!("abc", "r} {}"));
| ^^^^^^^^^^^^^^^^^^^^^^^ unmatched `}` in asm template string
|
= note: if you intended to print `}`, you can escape it using `}}`
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)

error: invalid asm template string: unmatched `}` found
--> $DIR/ice-bad-err-span-in-template-129503.rs:24:19
Loading