Skip to content

Revert FCW on lint attributes on macro calls - #165257

Open
mejrs wants to merge 1 commit into
rust-lang:mainfrom
mejrs:lint_check_maccall
Open

mejrs wants to merge 1 commit into
rust-lang:mainfrom
mejrs:lint_check_maccall

Conversation

@mejrs

@mejrs mejrs commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

In porting the lint attributes, it also added a fcw if they're used on a macro invocation. However t is something that has meaning, so revert the FCW.

// edition ..2021
macro_rules! wat {
    ($($tt:tt)*) => {}
}

fn main(){
    #[deny(keyword_idents_2024)]
    wat!(gen);
    //~^ ERROR `gen` is a keyword in the 2024 edition
    //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
}

So I don't think this should be a fcw.

Similarly, clippy currently does this:

fn main() {
    #[deny(clippy::nonstandard_macro_braces)]
    println! {};
}
error: use of irregular braces for `println!` macro
 --> src/main.rs:3:5
  |
3 |     println! {};
  |     ^^^^^^^^^^^ help: consider writing: `println!()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#nonstandard_macro_braces
note: the lint level is defined here
 --> src/main.rs:2:12
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the `deny` attribute cannot be used on macro calls
 --> src/main.rs:2:7
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |       ^^^^
3 |     println! {};
  |
  = help: the `deny` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
  = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default

@rustbot

rustbot commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@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 Oct 31, 2026
@rustbot

rustbot commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@mejrs
mejrs force-pushed the lint_check_maccall branch from f3ab317 to 1aed523 Compare October 31, 2026 21:58
Allow(Target::While),
Allow(Target::Break),
Warn(Target::MacroCall),
Allow(Target::MacroCall),

@JonathanBrouwer JonathanBrouwer Nov 2, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it makes sense to emit the warning iff none of the lints that are configured are pre-expansion lints. I'm not sure how easy that would be to implement tho...

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do have some cases where this is linted against based on the lint, like non_exhaustive_omitted_patterns on match arms for example.

@mejrs

mejrs commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

(It would be nice to get this in before the beta cutoff, otherwise it will require backporting)

@JonathanBrouwer

Copy link
Copy Markdown
Member

I think since this is a change to when a lint is emitted, the lang team needs to approve this.
If you'd like to get the specific regression fixed quickly, might be better to special-case this not to emit the FCW, but still emit an unused attributes warning.

@mejrs

mejrs commented Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

I think since this is a change to when a lint is emitted, the lang team needs to approve this.

It was added in #87296, without lang involvement. The FCW was added to it after I ported the lint attributes, again without lang involvement.

Both were probably mistakes. and the correct process would be to revert both and then (if desired) land it again with t-lang approval.

@JonathanBrouwer

JonathanBrouwer commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Since the lint has already been on stable for 5 years, and it is useful in most cases, I don't like removing it entirely, especially not without T-lang approval.

For example, the lint helps identify that lint attributes are not applied to the expanded code of a macro:

macro_rules! nice {
    () => {
        // mhuahuahua :D
        unsafe { *std::ptr::null::<()>() } //~ OK
    };
}

fn main(){
    #[deny(unsafe_code)]
    nice!();
}

(I'm still happy to revert the FCW part)

@mejrs

mejrs commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Sounds good, I'll do that.

@mejrs

mejrs commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

I think it would generally be a good idea to do a future PR to emit a lint for "this particular lint on this target doesn't make sense"

@JonathanBrouwer

Copy link
Copy Markdown
Member

I think it would generally be a good idea to do a future PR to emit a lint for "this particular lint on this target doesn't make sense"

Sounds like a good idea!

@mejrs
mejrs force-pushed the lint_check_maccall branch from 1aed523 to 6c7f841 Compare November 3, 2026 18:10
@rustbot

rustbot commented Nov 3, 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.

@mejrs mejrs changed the title Do not warn on lint check attributes on macro calls Revert FCW on lint attributes on macro calls Nov 3, 2026

@JonathanBrouwer JonathanBrouwer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6c7f841 has been approved by JonathanBrouwer

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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 4, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…anBrouwer

Revert FCW on lint attributes on macro calls

In porting the lint attributes, it also added a fcw if they're used on a macro invocation. However t is something that has meaning, so revert the FCW.

```rust
// edition ..2021
macro_rules! wat {
    ($($tt:tt)*) => {}
}

fn main(){
    #[deny(keyword_idents_2024)]
    wat!(gen);
    //~^ ERROR `gen` is a keyword in the 2024 edition
    //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
}
```

So I don't think this should be a fcw.

Similarly, clippy currently does this:
```rust
fn main() {
    #[deny(clippy::nonstandard_macro_braces)]
    println! {};
}
```
```rust
error: use of irregular braces for `println!` macro
 --> src/main.rs:3:5
  |
3 |     println! {};
  |     ^^^^^^^^^^^ help: consider writing: `println!()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#nonstandard_macro_braces
note: the lint level is defined here
 --> src/main.rs:2:12
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the `deny` attribute cannot be used on macro calls
 --> src/main.rs:2:7
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |       ^^^^
3 |     println! {};
  |
  = help: the `deny` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
  = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default
```
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…anBrouwer

Revert FCW on lint attributes on macro calls

In porting the lint attributes, it also added a fcw if they're used on a macro invocation. However t is something that has meaning, so revert the FCW.

```rust
// edition ..2021
macro_rules! wat {
    ($($tt:tt)*) => {}
}

fn main(){
    #[deny(keyword_idents_2024)]
    wat!(gen);
    //~^ ERROR `gen` is a keyword in the 2024 edition
    //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
}
```

So I don't think this should be a fcw.

Similarly, clippy currently does this:
```rust
fn main() {
    #[deny(clippy::nonstandard_macro_braces)]
    println! {};
}
```
```rust
error: use of irregular braces for `println!` macro
 --> src/main.rs:3:5
  |
3 |     println! {};
  |     ^^^^^^^^^^^ help: consider writing: `println!()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#nonstandard_macro_braces
note: the lint level is defined here
 --> src/main.rs:2:12
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the `deny` attribute cannot be used on macro calls
 --> src/main.rs:2:7
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |       ^^^^
3 |     println! {};
  |
  = help: the `deny` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
  = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default
```
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165376 (Add `Forget` trait feature gate)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165364 (Update books)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…anBrouwer

Revert FCW on lint attributes on macro calls

In porting the lint attributes, it also added a fcw if they're used on a macro invocation. However t is something that has meaning, so revert the FCW.

```rust
// edition ..2021
macro_rules! wat {
    ($($tt:tt)*) => {}
}

fn main(){
    #[deny(keyword_idents_2024)]
    wat!(gen);
    //~^ ERROR `gen` is a keyword in the 2024 edition
    //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
}
```

So I don't think this should be a fcw.

Similarly, clippy currently does this:
```rust
fn main() {
    #[deny(clippy::nonstandard_macro_braces)]
    println! {};
}
```
```rust
error: use of irregular braces for `println!` macro
 --> src/main.rs:3:5
  |
3 |     println! {};
  |     ^^^^^^^^^^^ help: consider writing: `println!()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#nonstandard_macro_braces
note: the lint level is defined here
 --> src/main.rs:2:12
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the `deny` attribute cannot be used on macro calls
 --> src/main.rs:2:7
  |
2 |     #[deny(clippy::nonstandard_macro_braces)]
  |       ^^^^
3 |     println! {};
  |
  = help: the `deny` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
  = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default
```
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #165376 (Add `Forget` trait feature gate)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165201 (Move a bunch of methods out of `AttributeExt`)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165364 (Update books)
 - #165414 (Remove unusued query key impl)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165440 (docker: bump node to v24.22.2 in shared script)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #165376 (Add `Forget` trait feature gate)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165201 (Move a bunch of methods out of `AttributeExt`)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165364 (Update books)
 - #165414 (Remove unusued query key impl)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165440 (docker: bump node to v24.22.2 in shared script)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #165376 (Add `Forget` trait feature gate)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165201 (Move a bunch of methods out of `AttributeExt`)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165364 (Update books)
 - #165414 (Remove unusued query key impl)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165440 (docker: bump node to v24.22.2 in shared script)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)

This branch has not been deployed

No deployments
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants