Skip to content

Implement #[diagnostic::opaque] attribute to hide backtraces of macros. - #158608

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
mejrs:opaque
Jul 15, 2026
Merged

Implement #[diagnostic::opaque] attribute to hide backtraces of macros.#158608
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
mejrs:opaque

Conversation

@mejrs

@mejrs mejrs commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

r? @estebank

There are some more places where we can use this, for example

let in_std_macro =
match obligation.cause.span.ctxt().outer_expn_data().macro_def_id {
Some(macro_def_id) => {
let crate_name = tcx.crate_name(macro_def_id.krate);
STDLIB_STABLE_CRATES.contains(&crate_name)
}
None => false,
};
if in_std_macro
&& matches!(
self.tcx.get_diagnostic_name(leaf_trait_predicate.def_id()),
Some(sym::Debug | sym::Display)
)
{
return err.emit();
}
but those turned out to be a little complicated so are left for followup prs.

Tracking issue: #158813

@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

rustc_errors::emitter was changed

cc @Muscraft

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Jun 30, 2026
@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 30, 2026
Comment thread compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 30, 2026
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 30, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/macros/mod.rs
@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@estebank

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 106bb96 has been approved by estebank

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 14, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 15, 2026
Rollup of 15 pull requests

Successful merges:

 - #159311 (Add 1.97.1 release notes)
 - #156220 (Implement `VecDeque::truncate_to_range`)
 - #158608 (Implement `#[diagnostic::opaque]` attribute to hide backtraces of macros.)
 - #159168 (Fix static_mut_refs lint check logic)
 - #159242 (resolve: Inherit eager invocation parents)
 - #159256 (Account for async closures when pointing at lifetime in return type)
 - #159310 (cleanup: upstream dropped AMX-TF32)
 - #158348 (Add documentation for the `inline` attribute)
 - #159181 (add rustc_no_writable to mem::forget and structs it uses)
 - #159191 (Mark `PrivateItems` with `std_internals` unstable feature.)
 - #159194 (rustdoc: Fix auto trait normalization env)
 - #159196 (OnceCell: Improve wording in module docs)
 - #159289 (Fix Zulip backport command suggestion)
 - #159294 (renovate: don't update PRs in the merge queue)
 - #159305 (std: clarify available_parallelism docs for Windows 11 processor groups)
@rust-bors
rust-bors Bot merged commit 2d4ae66 into rust-lang:main Jul 15, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 15, 2026
rust-timer added a commit that referenced this pull request Jul 15, 2026
Rollup merge of #158608 - mejrs:opaque, r=estebank

Implement `#[diagnostic::opaque]` attribute to hide backtraces of macros.

r? @estebank

There are some more places where we can use this, for example https://github.com/rust-lang/rust/blob/345632878cffcb4c8e90750e943296b43d16c76e/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs#L623-L639 but those turned out to be a little complicated so are left for followup prs.

Tracking issue: #158813
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Jul 16, 2026
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#159311 (Add 1.97.1 release notes)
 - rust-lang/rust#156220 (Implement `VecDeque::truncate_to_range`)
 - rust-lang/rust#158608 (Implement `#[diagnostic::opaque]` attribute to hide backtraces of macros.)
 - rust-lang/rust#159168 (Fix static_mut_refs lint check logic)
 - rust-lang/rust#159242 (resolve: Inherit eager invocation parents)
 - rust-lang/rust#159256 (Account for async closures when pointing at lifetime in return type)
 - rust-lang/rust#159310 (cleanup: upstream dropped AMX-TF32)
 - rust-lang/rust#158348 (Add documentation for the `inline` attribute)
 - rust-lang/rust#159181 (add rustc_no_writable to mem::forget and structs it uses)
 - rust-lang/rust#159191 (Mark `PrivateItems` with `std_internals` unstable feature.)
 - rust-lang/rust#159194 (rustdoc: Fix auto trait normalization env)
 - rust-lang/rust#159196 (OnceCell: Improve wording in module docs)
 - rust-lang/rust#159289 (Fix Zulip backport command suggestion)
 - rust-lang/rust#159294 (renovate: don't update PRs in the merge queue)
 - rust-lang/rust#159305 (std: clarify available_parallelism docs for Windows 11 processor groups)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 18, 2026
…ros, r=mejrs

Apply `#[diagnostic::opaque]` to macros expanding to built-in syntax

For context, thin wrapper macros expanding to built-in syntax `builtin # SYNTAX(…)` (internal feature `builtin_syntax`) is an alternative to built-in macros (`#[rustc_builtin_macro]`) for introducing new syntax constructs that takes slightly less code to implement in the compiler (since one doesn't need to write boiler-plate expanders, see RUST-122806 for example).

However, one disadvantage of that approach is the fact that the thin wrapper macro is a normal macro and is thus considered "interesting" wrt. macro backtraces. The fact that it expands to `builtin # SYNTAX(…)` should be considered an implementation detail and thus these macros should be considered opaque.

I've applied `#[diagnostic::opaque]` (rust-lang#158608) to all of these macros which successfully suppresses diagnostic notes of the form `` this error originates in the macro `SYNTAX` (…) ``. Well, it doesn't actually omit the expansion from the macro backtrace when `-Zmacro-backtrace` is passed which was surprising but seems intentional looking at the linked PR. Still, this is better than nothing.

r? @mejrs
rust-timer added a commit that referenced this pull request Jul 19, 2026
Rollup merge of #159522 - fmease:opaquify-builtin-syntax-macros, r=mejrs

Apply `#[diagnostic::opaque]` to macros expanding to built-in syntax

For context, thin wrapper macros expanding to built-in syntax `builtin # SYNTAX(…)` (internal feature `builtin_syntax`) is an alternative to built-in macros (`#[rustc_builtin_macro]`) for introducing new syntax constructs that takes slightly less code to implement in the compiler (since one doesn't need to write boiler-plate expanders, see RUST-122806 for example).

However, one disadvantage of that approach is the fact that the thin wrapper macro is a normal macro and is thus considered "interesting" wrt. macro backtraces. The fact that it expands to `builtin # SYNTAX(…)` should be considered an implementation detail and thus these macros should be considered opaque.

I've applied `#[diagnostic::opaque]` (#158608) to all of these macros which successfully suppresses diagnostic notes of the form `` this error originates in the macro `SYNTAX` (…) ``. Well, it doesn't actually omit the expansion from the macro backtrace when `-Zmacro-backtrace` is passed which was surprising but seems intentional looking at the linked PR. Still, this is better than nothing.

r? @mejrs
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Jul 19, 2026
Apply `#[diagnostic::opaque]` to macros expanding to built-in syntax

For context, thin wrapper macros expanding to built-in syntax `builtin # SYNTAX(…)` (internal feature `builtin_syntax`) is an alternative to built-in macros (`#[rustc_builtin_macro]`) for introducing new syntax constructs that takes slightly less code to implement in the compiler (since one doesn't need to write boiler-plate expanders, see RUST-122806 for example).

However, one disadvantage of that approach is the fact that the thin wrapper macro is a normal macro and is thus considered "interesting" wrt. macro backtraces. The fact that it expands to `builtin # SYNTAX(…)` should be considered an implementation detail and thus these macros should be considered opaque.

I've applied `#[diagnostic::opaque]` (rust-lang/rust#158608) to all of these macros which successfully suppresses diagnostic notes of the form `` this error originates in the macro `SYNTAX` (…) ``. Well, it doesn't actually omit the expansion from the macro backtrace when `-Zmacro-backtrace` is passed which was surprising but seems intentional looking at the linked PR. Still, this is better than nothing.

r? @mejrs
@lcnr lcnr added the relnotes Marks issues that should be documented in the release notes of the next release. label Jul 24, 2026
@mejrs

mejrs commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@lcnr this is unstable, I thought we only do relnotes for stuff that's getting stabilized?

@mejrs mejrs removed the relnotes Marks issues that should be documented in the release notes of the next release. label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants