Skip to content

Commit 0ac35c6

Browse files
committed
diagnostics: hide expansion of builtin-like macros
1 parent f8e9e76 commit 0ac35c6

File tree

68 files changed

+17
-167
lines changed

Some content is hidden

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

68 files changed

+17
-167
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 14 additions & 6 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

@@ -297,9 +297,16 @@ 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) => {
301-
Some((macro_kind, name, expn_data.hide_backtrace))
302-
}
300+
ExpnKind::Macro(macro_kind, name) => Some((
301+
macro_kind,
302+
name,
303+
expn_data.hide_backtrace
304+
|| expn_data.allow_internal_unstable.is_some_and(|aiu| {
305+
aiu.contains(&sym::fmt_internals)
306+
|| aiu.contains(&sym::print_internals)
307+
|| aiu.contains(&sym::liballoc_internals)
308+
}),
309+
)),
303310
}
304311
})
305312
.collect();
@@ -311,8 +318,9 @@ pub trait Emitter: Translate {
311318
self.render_multispans_macro_backtrace(span, children, backtrace);
312319

313320
if !backtrace {
314-
// Skip builtin macros, as their expansion isn't relevant to the end user. This includes
315-
// actual intrinsics, like `asm!`.
321+
// Skip some special macros, as their expansion isn't relevant to the end user.
322+
// This includes actual intrinsics and builtins like `asm!`, as well as macros
323+
// that contain implementation details like the formatting macros
316324
if let Some((macro_kind, name, _)) = has_macro_spans.first()
317325
&& let Some((_, _, false)) = has_macro_spans.last()
318326
{

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",

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

tests/ui/async-await/unreachable-lint-2.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ note: the lint level is defined here
1111
|
1212
LL | #![deny(unreachable_code)]
1313
| ^^^^^^^^^^^^^^^^
14-
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1514

1615
error: aborting due to 1 previous error
1716

tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LL | test(&vec![])
88
| argument requires that borrow lasts for `'static`
99
LL | }
1010
| - temporary value is freed at the end of this statement
11-
|
12-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1311

1412
error: aborting due to 1 previous error
1513

tests/ui/borrowck/borrowck-and-init.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LL | println!("{}", false && { i = 5; true });
88
| ----- binding initialized here in some conditions
99
LL | println!("{}", i);
1010
| ^ `i` used here but it is possibly-uninitialized
11-
|
12-
= 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)
1311

1412
error: aborting due to 1 previous error
1513

tests/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ LL | let x = defer(&vec!["Goodbye", "world!"]);
88
LL | x.x[0];
99
| ------ borrow later used here
1010
|
11-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1211
help: consider using a `let` binding to create a longer lived value
1312
|
1413
LL ~ let binding = vec!["Goodbye", "world!"];

tests/ui/borrowck/borrowck-break-uninit-2.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | let x: isize;
77
LL | println!("{}", x);
88
| ^ `x` used here but it isn't initialized
99
|
10-
= 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)
1110
help: consider assigning a value
1211
|
1312
LL | let x: isize = 42;

tests/ui/borrowck/borrowck-break-uninit.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | let x: isize;
77
LL | println!("{}", x);
88
| ^ `x` used here but it isn't initialized
99
|
10-
= 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)
1110
help: consider assigning a value
1211
|
1312
LL | let x: isize = 42;

0 commit comments

Comments
 (0)