Skip to content

diagnostics: hide expansion of builtin-like macros #141314

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented May 20, 2025

As of late I've gotten more and more annoyed by notes like note: this error originates in the macro $crate::__export::format_args.

This PR hides that message if it comes from an expansion of a macro that uses features like fmt_internals. If its expansion is an implementation detail we shouldn't be mentioning it. This covers macros like vec!, format! and so on, but not the more mundane ones like assert_eq! and todo!!

@rustbot
Copy link
Collaborator

rustbot commented May 20, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 20, 2025
@rust-log-analyzer

This comment has been minimized.

|| aiu.contains(&sym::print_internals)
|| aiu.contains(&sym::liballoc_internals)
}),
)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth pulling everything after the first || out into a separate variable.

Also, I don't really understand how this works, i.e. how allow_internal_unstable is involved. A brief comment explaining it would be useful.

@nnethercote
Copy link
Contributor

Generally looks good, I will r+ once the tests all pass the the suggestion above is addressed. Thanks.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 21, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@@ -193,16 +193,12 @@ error: asm template must be a string literal
|
LL | asm!(format!("{{{}}}", 0), in(reg) foo);
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does -Zmacro-backtrace still work for builtin-like macros with this PR?

@petrochenkov
Copy link
Contributor

I just recently rejected this change in #138379.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/function_calls/exported_symbol_bad_unwind2.rs (revision `definition`) ... ok
tests/fail/function_calls/exported_symbol_bad_unwind2.rs (revision `both`) ... ok

FAILED TEST: tests/fail/erroneous_const2.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-WnPdKX" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail" "tests/fail/erroneous_const2.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/erroneous_const2.stderr` to the actual output
--- tests/fail/erroneous_const2.stderr
+++ <stderr output>
---
   |
LL |     println!("{}", FOO);
   |                    ^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
  --> tests/fail/erroneous_const2.rs:8:20
   |
LL |     println!("{}", FOO);
---
   |
LL |     println!("{}", FOO);
   |                    ^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
  --> tests/fail/erroneous_const2.rs:8:20
   |
LL |     println!("{}", FOO);
---



FAILED TEST: tests/fail/dangling_pointers/out_of_bounds_read.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-WnPdKX" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/dangling_pointers" "tests/fail/dangling_pointers/out_of_bounds_read.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/dangling_pointers/out_of_bounds_read.stderr` to the actual output
--- tests/fail/dangling_pointers/out_of_bounds_read.stderr
+++ <stderr output>
 error: Undefined Behavior: memory access failed: attempting to access 2 bytes, but got ALLOC+0x5 which is at or beyond the end of the allocation of size 4 bytes
   --> tests/fail/dangling_pointers/out_of_bounds_read.rs:LL:CC
... 11 lines skipped ...
    = note: BACKTRACE (of the first span):
    = note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_read.rs:LL:CC
-   = note: this error originates in the macro `vec` (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
 
 error: aborting due to 1 previous error
 

Full unnormalized output:
error: Undefined Behavior: memory access failed: attempting to access 2 bytes, but got alloc398+0x5 which is at or beyond the end of the allocation of size 4 bytes
##[error]  --> tests/fail/dangling_pointers/out_of_bounds_read.rs:4:22
   |
LL |     let x = unsafe { *v.as_ptr().wrapping_byte_add(5) };
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: attempting to access 2 bytes, but got alloc398+0x5 which is at or beyond the end of the allocation of size 4 bytes
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc398 was allocated here:
  --> tests/fail/dangling_pointers/out_of_bounds_read.rs:2:23
   |
LL |     let v: Vec<u16> = vec![1, 2];
   |                       ^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_read.rs:4:22: 4:54

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

error: aborting due to 1 previous error



full stderr:
error: Undefined Behavior: memory access failed: attempting to access 2 bytes, but got alloc398+0x5 which is at or beyond the end of the allocation of size 4 bytes
##[error]  --> tests/fail/dangling_pointers/out_of_bounds_read.rs:4:22
   |
LL |     let x = unsafe { *v.as_ptr().wrapping_byte_add(5) };
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: attempting to access 2 bytes, but got alloc398+0x5 which is at or beyond the end of the allocation of size 4 bytes
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc398 was allocated here:
  --> tests/fail/dangling_pointers/out_of_bounds_read.rs:2:23
   |
LL |     let v: Vec<u16> = vec![1, 2];
   |                       ^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_read.rs:4:22: 4:54

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



FAILED TEST: tests/fail/dangling_pointers/out_of_bounds_write.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-WnPdKX" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/dangling_pointers" "tests/fail/dangling_pointers/out_of_bounds_write.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/dangling_pointers/out_of_bounds_write.stderr` to the actual output
--- tests/fail/dangling_pointers/out_of_bounds_write.stderr
+++ <stderr output>
 error: Undefined Behavior: memory access failed: attempting to access 2 bytes, but got ALLOC+0x5 which is at or beyond the end of the allocation of size 4 bytes
   --> tests/fail/dangling_pointers/out_of_bounds_write.rs:LL:CC
... 11 lines skipped ...
    = note: BACKTRACE (of the first span):
    = note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_write.rs:LL:CC
-   = note: this error originates in the macro `vec` (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
 
 error: aborting due to 1 previous error
 

Full unnormalized output:
error: Undefined Behavior: memory access failed: attempting to access 2 bytes, but got alloc394+0x5 which is at or beyond the end of the allocation of size 4 bytes
##[error]  --> tests/fail/dangling_pointers/out_of_bounds_write.rs:4:14
   |
LL |     unsafe { *v.as_mut_ptr().wrapping_byte_add(5) = 0 };
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: attempting to access 2 bytes, but got alloc394+0x5 which is at or beyond the end of the allocation of size 4 bytes
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc394 was allocated here:
  --> tests/fail/dangling_pointers/out_of_bounds_write.rs:2:27
   |
LL |     let mut v: Vec<u16> = vec![1, 2];
   |                           ^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_write.rs:4:14: 4:54

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

error: aborting due to 1 previous error



full stderr:
error: Undefined Behavior: memory access failed: attempting to access 2 bytes, but got alloc394+0x5 which is at or beyond the end of the allocation of size 4 bytes
##[error]  --> tests/fail/dangling_pointers/out_of_bounds_write.rs:4:14
   |
LL |     unsafe { *v.as_mut_ptr().wrapping_byte_add(5) = 0 };
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: attempting to access 2 bytes, but got alloc394+0x5 which is at or beyond the end of the allocation of size 4 bytes
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc394 was allocated here:
  --> tests/fail/dangling_pointers/out_of_bounds_write.rs:2:27
   |
LL |     let mut v: Vec<u16> = vec![1, 2];
   |                           ^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at tests/fail/dangling_pointers/out_of_bounds_write.rs:4:14: 4:54

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



FAILED TEST: tests/fail/intrinsics/simd-scatter.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-WnPdKX" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/intrinsics" "tests/fail/intrinsics/simd-scatter.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/intrinsics/simd-scatter.stderr` to the actual output
--- tests/fail/intrinsics/simd-scatter.stderr
+++ <stderr output>
 error: Undefined Behavior: memory access failed: attempting to access 1 byte, but got ALLOC+0x9 which is at or beyond the end of the allocation of size 9 bytes
   --> tests/fail/intrinsics/simd-scatter.rs:LL:CC
... 16 lines skipped ...
    = note: BACKTRACE (of the first span):
    = note: inside `main` at tests/fail/intrinsics/simd-scatter.rs:LL:CC
-   = note: this error originates in the macro `vec` (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
 
 error: aborting due to 1 previous error
 

Full unnormalized output:
error: Undefined Behavior: memory access failed: attempting to access 1 byte, but got alloc394+0x9 which is at or beyond the end of the allocation of size 9 bytes
##[error]  --> tests/fail/intrinsics/simd-scatter.rs:8:9
   |
LL | /         Simd::from_array([-27, 82, -41, 124]).scatter_select_unchecked(
LL | |
LL | |             &mut vec,
LL | |             Mask::splat(true),
LL | |             idxs,
LL | |         );
   | |_________^ memory access failed: attempting to access 1 byte, but got alloc394+0x9 which is at or beyond the end of the allocation of size 9 bytes
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc394 was allocated here:
  --> tests/fail/intrinsics/simd-scatter.rs:6:32
   |
LL |         let mut vec: Vec<i8> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at tests/fail/intrinsics/simd-scatter.rs:8:9: 13:10

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

error: aborting due to 1 previous error



full stderr:
error: Undefined Behavior: memory access failed: attempting to access 1 byte, but got alloc394+0x9 which is at or beyond the end of the allocation of size 9 bytes
##[error]  --> tests/fail/intrinsics/simd-scatter.rs:8:9
   |
LL | /         Simd::from_array([-27, 82, -41, 124]).scatter_select_unchecked(
LL | |
LL | |             &mut vec,
LL | |             Mask::splat(true),
LL | |             idxs,
LL | |         );
   | |_________^ memory access failed: attempting to access 1 byte, but got alloc394+0x9 which is at or beyond the end of the allocation of size 9 bytes
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc394 was allocated here:
  --> tests/fail/intrinsics/simd-scatter.rs:6:32
   |
LL |         let mut vec: Vec<i8> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at tests/fail/intrinsics/simd-scatter.rs:8:9: 13:10

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



FAILED TEST: tests/fail/tree_borrows/protector-write-lazy.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-WnPdKX" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/tree_borrows" "tests/fail/tree_borrows/protector-write-lazy.rs" "-Zmiri-tree-borrows" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/tree_borrows/protector-write-lazy.stderr` to the actual output
--- tests/fail/tree_borrows/protector-write-lazy.stderr
+++ <stderr output>
 error: Undefined Behavior: reborrow through <TAG> at ALLOC[0x0] is forbidden
   --> tests/fail/tree_borrows/protector-write-lazy.rs:LL:CC
... 17 lines skipped ...
    = note: BACKTRACE (of the first span):
    = note: inside `main` at tests/fail/tree_borrows/protector-write-lazy.rs:LL:CC
-   = 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)
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
 
 error: aborting due to 1 previous error
 

Full unnormalized output:
error: Undefined Behavior: reborrow through <826> at alloc400[0x0] is forbidden
##[error]  --> tests/fail/tree_borrows/protector-write-lazy.rs:34:45
   |
LL |     unsafe { println!("Value of funky: {}", *funky_ptr_lazy_on_fst_elem) }
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ reborrow through <826> at alloc400[0x0] is forbidden
   |
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
   = help: the accessed tag <826> has state Disabled which forbids this reborrow (acting as a child read access)
help: the accessed tag <826> was created here, in the initial state Reserved
  --> tests/fail/tree_borrows/protector-write-lazy.rs:17:18
   |
LL |         unsafe { (&mut *(ptr_to_vec.wrapping_add(1))) as *mut i32 }.wrapping_sub(1);
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: the accessed tag <826> later transitioned to Disabled due to a protector release (acting as a foreign write access) on every location previously accessed by this tag
  --> tests/fail/tree_borrows/protector-write-lazy.rs:22:2
   |
LL | }
   |  ^
   = help: this transition corresponds to a loss of read and write permissions
---



full stderr:
error: Undefined Behavior: reborrow through <826> at alloc400[0x0] is forbidden
##[error]  --> tests/fail/tree_borrows/protector-write-lazy.rs:34:45
   |
LL |     unsafe { println!("Value of funky: {}", *funky_ptr_lazy_on_fst_elem) }
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ reborrow through <826> at alloc400[0x0] is forbidden
   |
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
   = help: the accessed tag <826> has state Disabled which forbids this reborrow (acting as a child read access)
help: the accessed tag <826> was created here, in the initial state Reserved
  --> tests/fail/tree_borrows/protector-write-lazy.rs:17:18
   |
LL |         unsafe { (&mut *(ptr_to_vec.wrapping_add(1))) as *mut i32 }.wrapping_sub(1);
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: the accessed tag <826> later transitioned to Disabled due to a protector release (acting as a foreign write access) on every location previously accessed by this tag
  --> tests/fail/tree_borrows/protector-write-lazy.rs:22:2
   |
LL | }
   |  ^
   = help: this transition corresponds to a loss of read and write permissions
---

Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.29.2/src/lib.rs:369

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/ui-5a4f22761d8182b7` (exit status: 1)
Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:04:42
  local time: Wed May 21 13:00:45 UTC 2025
  network time: Wed, 21 May 2025 13:00:45 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants