Skip to content

Conversation

joshtriplett
Copy link
Member

This implements unsafe attr rules for declarative macro_rules! attributes, as specified in RFC 3697.

An invocation of an attribute that uses an unsafe attr rule requires the unsafe(attr(...)) syntax.

An invocation of an attribute that uses an ordinary attr rule must not use the unsafe(attr(...)) syntax.

unsafe is only supported on an attr rule, not any other kind of macro_rules! rule.

Tracking issue for macro_rules! attributes: #143547

@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Sep 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
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

@joshtriplett joshtriplett added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Sep 14, 2025
@joshtriplett
Copy link
Member Author

r? @petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned davidtwco Sep 14, 2025
Copy link
Contributor

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

While I was preparing a talk for the Rust 4linux summit, I did a first pass on this, and it looks good!

Will do a final pass on it next week

Thanks for bringing this forward

View changes since this review

@petrochenkov petrochenkov 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 Sep 25, 2025
@joshtriplett
Copy link
Member Author

@rustbot ready

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

r=me with the comments updated and review commits squashed.
@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 Sep 29, 2025
@joshtriplett joshtriplett force-pushed the mbe-unsafe-attr branch 2 times, most recently from 8295ecd to 42c3f40 Compare October 1, 2025 23:18
This simplifies subsequent initialization of enum variants.
… `LegacyAttr` here

`LegacyAttr` is only used for builtin attributes, and builtin attributes
have their safety checked by `check_attribute_safety`, so we don't need
to check `unsafety` here.
@rustbot
Copy link
Collaborator

rustbot commented Oct 1, 2025

This PR was rebased onto a different master 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.

@joshtriplett
Copy link
Member Author

@bors r=petrochenkov rollup

@bors
Copy link
Collaborator

bors commented Oct 1, 2025

📌 Commit 4fc0a0d has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors 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 Oct 1, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 2, 2025
…trochenkov

mbe: Implement `unsafe` attribute rules

This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](rust-lang/rfcs#3697).

An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax.

An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax.

`unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule.

Tracking issue for `macro_rules!` attributes: rust-lang#143547
bors added a commit that referenced this pull request Oct 2, 2025
Rollup of 10 pull requests

Successful merges:

 - #146281 (Support `#[rustc_align_static]` inside `thread_local!`)
 - #146535 (mbe: Implement `unsafe` attribute rules)
 - #146585 (indexing: reword help)
 - #147004 (Tweak handling of "struct like start" where a struct isn't supported)
 - #147221 (Forbid `//@ compile-flags: -Cincremental=` in tests)
 - #147225 (Don't enable shared memory by default with Wasm atomics)
 - #147227 (implement `Box::take`)
 - #147231 (Extending `#[rustc_force_inline]` to be applicable to inherent methods)
 - #147233 (Initialize llvm submodule if not already the case to run citool)
 - #147236 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 2, 2025
…trochenkov

mbe: Implement `unsafe` attribute rules

This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](rust-lang/rfcs#3697).

An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax.

An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax.

`unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule.

Tracking issue for `macro_rules!` attributes: rust-lang#143547
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 2, 2025
…trochenkov

mbe: Implement `unsafe` attribute rules

This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](rust-lang/rfcs#3697).

An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax.

An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax.

`unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule.

Tracking issue for `macro_rules!` attributes: rust-lang#143547
bors added a commit that referenced this pull request Oct 2, 2025
Rollup of 9 pull requests

Successful merges:

 - #146281 (Support `#[rustc_align_static]` inside `thread_local!`)
 - #146535 (mbe: Implement `unsafe` attribute rules)
 - #146585 (indexing: reword help)
 - #147004 (Tweak handling of "struct like start" where a struct isn't supported)
 - #147221 (Forbid `//@ compile-flags: -Cincremental=` in tests)
 - #147225 (Don't enable shared memory by default with Wasm atomics)
 - #147227 (implement `Box::take`)
 - #147233 (Initialize llvm submodule if not already the case to run citool)
 - #147236 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ac7beab into rust-lang:master Oct 2, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 2, 2025
rust-timer added a commit that referenced this pull request Oct 2, 2025
Rollup merge of #146535 - joshtriplett:mbe-unsafe-attr, r=petrochenkov

mbe: Implement `unsafe` attribute rules

This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](rust-lang/rfcs#3697).

An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax.

An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax.

`unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule.

Tracking issue for `macro_rules!` attributes: #143547
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 3, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#146281 (Support `#[rustc_align_static]` inside `thread_local!`)
 - rust-lang/rust#146535 (mbe: Implement `unsafe` attribute rules)
 - rust-lang/rust#146585 (indexing: reword help)
 - rust-lang/rust#147004 (Tweak handling of "struct like start" where a struct isn't supported)
 - rust-lang/rust#147221 (Forbid `//@ compile-flags: -Cincremental=` in tests)
 - rust-lang/rust#147225 (Don't enable shared memory by default with Wasm atomics)
 - rust-lang/rust#147227 (implement `Box::take`)
 - rust-lang/rust#147233 (Initialize llvm submodule if not already the case to run citool)
 - rust-lang/rust#147236 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants