Commit 0489fb0
authored
Rollup merge of #158814 - tahadostifam:taha_refactors_rustc_attr_parsing, r=JonathanBrouwer
Produce an error when `#[inline]` and `#[rust_force_inline]` are used together
### Merged RustcForceInline & Inline Attribute Parsers
I've been reading [https://github.com/rust-lang/rust/issues/153101](https://github.com/rust-lang/rust/issues/153101), #131229 and I came across with this comment in `compiler/rustc_attr_parsing/src/attributes/inline.rs`:
```rust
// FIXME(jdonszelmann): merge these two parsers and error when both attributes are present here.
// note: need to model better how duplicate attr errors work when not using
// SingleAttributeParser which is what we have two of here.
```
Having separate `SingleAttributeParser` implementations for `#[rustc_force_inline]` and `#[inline(...)]` meant the compiler wasn't able to recognize cases where both of them were used together on the same item, for example:
```rust
#![feature(rustc_attrs)]
#[rustc_force_inline]
#[inline]
fn foo() {}
fn main() {}
```
<img width="1222" height="915" alt="image" src="https://github.com/user-attachments/assets/69d4e3b0-bc21-4679-8f3d-017f9fe152fb" />
This case was previously considered allowed, which is not correct.
My changes replace the distinct attribute parsers with a single unified `AttributeParser` implementation for `InlineParser`, handling both attributes together in a single pass. By consolidating the logic, the parser now tracks the state of both attributes side-by-side using an `AcceptMapping` and introduces a new session diagnostic, `InlineForceInlineConflict`, which is explicitly triggered in the `finalize` step if a user attempts to combine them.
An added benefit of catching this conflict early during the parsing phase is that it prevents downstream validation passes (like `check_attr`) from triggering redundant errors on malformed or incorrectly placed attributes, which naturally cleans up and streamlines our compiler stderr output as reflected in the updated UI test baselines.
**This is my very first PR on rustc**, and I am incredibly grateful to @hkalbasi, who heavily guided me through the codebase and helped make this change possible!
Sincerely looking for your feedback and thoughts on this, let me know if there is something need to be changed.4 files changed
Lines changed: 52 additions & 4 deletions
File tree
- compiler/rustc_attr_parsing/src
- attributes
- tests/ui/attributes/inline
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | 1 | | |
6 | 2 | | |
| 3 | + | |
7 | 4 | | |
8 | 5 | | |
9 | 6 | | |
| 7 | + | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
97 | 107 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments