Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f0b8e13

Browse files
committedMar 14, 2025·
Do not suggest using -Zmacro-backtrace for builtin macros
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
1 parent f7b4354 commit f0b8e13

File tree

205 files changed

+27
-495
lines changed

Some content is hidden

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

205 files changed

+27
-495
lines changed
 

‎compiler/rustc_errors/src/emitter.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ pub trait Emitter: Translate {
297297
// are some which do actually involve macros.
298298
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
299299

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

311313
if !backtrace {
312-
if let Some((macro_kind, name)) = has_macro_spans.first() {
314+
// Skip builtin macros, as their expansion isn't relevant to the end user. This includes
315+
// actual intrinsics, like `asm!`.
316+
if let Some((macro_kind, name, _)) = has_macro_spans.first()
317+
&& let Some((_, _, false)) = has_macro_spans.last()
318+
{
313319
// Mark the actual macro this originates from
314-
let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
320+
let and_then = if let Some((macro_kind, last_name, _)) = has_macro_spans.last()
315321
&& last_name != name
316322
{
317323
let descr = macro_kind.descr();
318-
format!(" which comes from the expansion of the {descr} `{last_name}`",)
324+
format!(" which comes from the expansion of the {descr} `{last_name}`")
319325
} else {
320326
"".to_string()
321327
};

‎compiler/rustc_expand/src/base.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,16 @@ impl SyntaxExtension {
889889
})
890890
.unwrap_or_else(|| (None, helper_attrs));
891891

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

894894
// FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem
895-
if let Some(sp) = find_attr!(attrs, AttributeKind::ConstStability{span, ..} => *span) {
895+
if let Some(sp) = find_attr!(attrs, AttributeKind::ConstStability { span, .. } => *span) {
896896
sess.dcx().emit_err(errors::MacroConstStability {
897897
span: sp,
898898
head_span: sess.source_map().guess_head_span(span),
899899
});
900900
}
901-
if let Some(sp) = find_attr!(attrs, AttributeKind::BodyStability{span, ..} => *span) {
901+
if let Some(sp) = find_attr!(attrs, AttributeKind::BodyStability{ span, .. } => *span) {
902902
sess.dcx().emit_err(errors::MacroBodyStability {
903903
span: sp,
904904
head_span: sess.source_map().guess_head_span(span),
@@ -912,7 +912,10 @@ impl SyntaxExtension {
912912
// FIXME(jdonszelmann): avoid the into_iter/collect?
913913
.then(|| allow_internal_unstable.iter().map(|i| i.0).collect::<Vec<_>>().into()),
914914
stability,
915-
deprecation: find_attr!(attrs, AttributeKind::Deprecation{deprecation, ..} => *deprecation),
915+
deprecation: find_attr!(
916+
attrs,
917+
AttributeKind::Deprecation { deprecation, .. } => *deprecation
918+
),
916919
helper_attrs,
917920
edition,
918921
builtin_name,
@@ -1000,6 +1003,7 @@ impl SyntaxExtension {
10001003
self.allow_internal_unsafe,
10011004
self.local_inner_macros,
10021005
self.collapse_debuginfo,
1006+
self.builtin_name.is_some(),
10031007
)
10041008
}
10051009
}

0 commit comments

Comments
 (0)
Please sign in to comment.