Skip to content

Commit 72d9368

Browse files
committed
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",

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LL | let v: Vec<u16> = vec![1, 2];
1313
| ^^^^^^^^^^
1414
= note: BACKTRACE (of the first span):
1515
= note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_read.rs:LL:CC
16-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1716

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

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_write.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LL | let mut v: Vec<u16> = vec![1, 2];
1313
| ^^^^^^^^^^
1414
= note: BACKTRACE (of the first span):
1515
= note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_write.rs:LL:CC
16-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1716

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

src/tools/miri/tests/fail/erroneous_const2.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ note: erroneous constant encountered
2323
|
2424
LL | println!("{}", FOO);
2525
| ^^^
26-
|
27-
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
2826

2927
error: aborting due to 1 previous error
3028

src/tools/miri/tests/fail/intrinsics/simd-scatter.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ LL | let mut vec: Vec<i8> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
= note: BACKTRACE (of the first span):
2020
= note: inside `main` at tests/fail/intrinsics/simd-scatter.rs:LL:CC
21-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
2221

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

src/tools/miri/tests/fail/tree_borrows/protector-write-lazy.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ LL | }
1919
= help: this transition corresponds to a loss of read and write permissions
2020
= note: BACKTRACE (of the first span):
2121
= note: inside `main` at tests/fail/tree_borrows/protector-write-lazy.rs:LL:CC
22-
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
2322

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

tests/rustdoc-ui/doctest/main-alongside-macro-calls.fail.stdout

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ error: macros that expand to items must be delimited with braces or followed by
1313
|
1414
LL | println!();
1515
| ^^^^^^^^^^
16-
|
17-
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1816

1917
error: macro expansion ignores `{` and any tokens following
2018
--> $SRC_DIR/std/src/macros.rs:LL:COL
@@ -35,8 +33,6 @@ error: macros that expand to items must be delimited with braces or followed by
3533
|
3634
LL | println!();
3735
| ^^^^^^^^^^
38-
|
39-
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
4036

4137
error: macro expansion ignores `{` and any tokens following
4238
--> $SRC_DIR/std/src/macros.rs:LL:COL

tests/ui/asm/parse-error.stderr

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,12 @@ error: asm template must be a string literal
193193
|
194194
LL | asm!(format!("{{{}}}", 0), in(reg) foo);
195195
| ^^^^^^^^^^^^^^^^^^^^
196-
|
197-
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
198196

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

207203
error: _ cannot be used for input operands
208204
--> $DIR/parse-error.rs:88:28
@@ -357,16 +353,12 @@ error: asm template must be a string literal
357353
|
358354
LL | global_asm!(format!("{{{}}}", 0), const FOO);
359355
| ^^^^^^^^^^^^^^^^^^^^
360-
|
361-
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
362356

363357
error: asm template must be a string literal
364358
--> $DIR/parse-error.rs:143:20
365359
|
366360
LL | global_asm!("{1}", format!("{{{}}}", 0), const FOO, const BAR);
367361
| ^^^^^^^^^^^^^^^^^^^^
368-
|
369-
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
370362

371363
error: the `in` operand cannot be used with `global_asm!`
372364
--> $DIR/parse-error.rs:146:19

tests/ui/asm/x86_64/type-check-2.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ LL | asm!("{}", in(reg) vec![0]);
2121
| ^^^^^^^
2222
|
2323
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
24-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
2524

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

0 commit comments

Comments
 (0)