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 72d9368

Browse files
committedMay 21, 2025·
diagnostics: hide expansion of builtin-like macros
1 parent f8e9e76 commit 72d9368

File tree

80 files changed

+147
-175
lines changed

Some content is hidden

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

80 files changed

+147
-175
lines changed
 

‎compiler/rustc_errors/src/emitter.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_lexer;
2424
use rustc_lint_defs::pluralize;
2525
use rustc_span::hygiene::{ExpnKind, MacroKind};
2626
use rustc_span::source_map::SourceMap;
27-
use rustc_span::{FileLines, FileName, SourceFile, Span, char_width, str_width};
27+
use rustc_span::{FileLines, FileName, SourceFile, Span, char_width, str_width, sym};
2828
use termcolor::{Buffer, BufferWriter, Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
2929
use tracing::{debug, instrument, trace, warn};
3030

@@ -298,7 +298,17 @@ pub trait Emitter: Translate {
298298
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
299299

300300
ExpnKind::Macro(macro_kind, name) => {
301-
Some((macro_kind, name, expn_data.hide_backtrace))
301+
// Don't recommend using `-Zmacro-backtrace` if
302+
// - hide_backtrace is true, which it is for builtin macros
303+
// - if the macro uses internal features so their expansion is unlikely to be useful
304+
let hide_macro_backtrace_suggestion = expn_data.hide_backtrace
305+
|| expn_data.allow_internal_unstable.is_some_and(|aiu| {
306+
aiu.contains(&sym::fmt_internals)
307+
|| aiu.contains(&sym::print_internals)
308+
|| aiu.contains(&sym::liballoc_internals)
309+
});
310+
311+
Some((macro_kind, name, hide_macro_backtrace_suggestion))
302312
}
303313
}
304314
})
@@ -311,8 +321,9 @@ pub trait Emitter: Translate {
311321
self.render_multispans_macro_backtrace(span, children, backtrace);
312322

313323
if !backtrace {
314-
// Skip builtin macros, as their expansion isn't relevant to the end user. This includes
315-
// actual intrinsics, like `asm!`.
324+
// Skip some special macros, as their expansion isn't relevant to the end user.
325+
// This includes actual intrinsics and builtins like `asm!`, as well as macros
326+
// that contain implementation details like the formatting macros
316327
if let Some((macro_kind, name, _)) = has_macro_spans.first()
317328
&& let Some((_, _, false)) = has_macro_spans.last()
318329
{

‎compiler/rustc_span/src/symbol.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ symbols! {
10071007
fmaf64,
10081008
fmt,
10091009
fmt_debug,
1010+
fmt_internals,
10101011
fmul_algebraic,
10111012
fmul_fast,
10121013
fmuladdf128,
@@ -1240,6 +1241,7 @@ symbols! {
12401241
let_else,
12411242
lhs,
12421243
lib,
1244+
liballoc_internals,
12431245
libc,
12441246
lifetime,
12451247
lifetime_capture_rules_2024,
@@ -1623,6 +1625,7 @@ symbols! {
16231625
prelude_import,
16241626
preserves_flags,
16251627
prfchw_target_feature,
1628+
print_internals,
16261629
print_macro,
16271630
println_macro,
16281631
proc_dash_macro: "proc-macro",

0 commit comments

Comments
 (0)
Please sign in to comment.