Apply #[diagnostic::opaque] to macros expanding to built-in syntax#159522
Merged
rust-bors[bot] merged 1 commit intoJul 19, 2026
Conversation
fmease
commented
Jul 18, 2026
| #[allow_internal_unstable(builtin_syntax, core_intrinsics)] | ||
| #[rustc_diagnostic_opaque] | ||
| pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) { | ||
| // The `{}` is for better error messages |
Member
Author
There was a problem hiding this comment.
It used to be a normal block but since RUST-148151 it is (and has to be) a const block since it gets lowered to calls to core::intrinsics::offset_of which is effectively #[rustc_comptime]1.
Footnotes
-
Currently, it lacks that attribute but that's just an oversight I'm certain. I'm gonna rectify that in a separate PR. ↩
This comment has been minimized.
This comment has been minimized.
fmease
force-pushed
the
opaquify-builtin-syntax-macros
branch
from
July 18, 2026 15:51
b90d221 to
d73a269
Compare
mejrs
reviewed
Jul 18, 2026
Contributor
There was a problem hiding this comment.
Can you use #[diagnostic::opaque] instead? The rustc variant exists to work around #98291, but that shouldn't be necessary for decl macros
fmease
force-pushed
the
opaquify-builtin-syntax-macros
branch
from
July 18, 2026 16:41
d73a269 to
a4142b7
Compare
#[rustc_diagnostic_opaque] to macros expanding to built-in syntax#[diagnostic::opaque] to macros expanding to built-in syntax
Member
Author
|
Applied. |
Contributor
rust-bors Bot
pushed a commit
that referenced
this pull request
Jul 18, 2026
…uwer Rollup of 6 pull requests Successful merges: - #159517 (stdarch subtree update) - #159010 (Simplify the unwind crate) - #156650 (Stop using prefix_tys) - #159152 (triagebot: cc miri on any special-casing of miri in the standard library) - #159522 (Apply `#[diagnostic::opaque]` to macros expanding to built-in syntax) - #159528 (implement `const_binary_search`)
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
…uwer Rollup of 6 pull requests Successful merges: - rust-lang/rust#159517 (stdarch subtree update) - rust-lang/rust#159010 (Simplify the unwind crate) - rust-lang/rust#156650 (Stop using prefix_tys) - rust-lang/rust#159152 (triagebot: cc miri on any special-casing of miri in the standard library) - rust-lang/rust#159522 (Apply `#[diagnostic::opaque]` to macros expanding to built-in syntax) - rust-lang/rust#159528 (implement `const_binary_search`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For context, thin wrapper macros expanding to built-in syntax
builtin # SYNTAX(…)(internal featurebuiltin_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 formthis error originates in the macro `SYNTAX` (…). Well, it doesn't actually omit the expansion from the macro backtrace when-Zmacro-backtraceis passed which was surprising but seems intentional looking at the linked PR. Still, this is better than nothing.r? @mejrs