-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(items): Take into account multi-line outer macro attributes
We properly handle multi-line attributes in front of an enum variant. There are several types of attributes [1], but the only attributes that can occur in this context are outer attributes like `#[repr(transparent)]`, `/// Example` or `/** Example */`. This commit deals with macro attributes like `#[repr(transparent)]`. We implement our own trivial macro attribute parser to exclude them from the variant definition, as we could not find a easy way of re-using existing parsing code (with the `syn` crate or `rustc_parse`). We will deal with outer documentation blocks in the next commit. [1] https://docs.rs/syn/2.0.75/syn/struct.Attribute.html
- Loading branch information
1 parent
5601462
commit 277cb90
Showing
2 changed files
with
100 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
tests/target/attribute-in-enum/vertical-macro-multi-line.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// rustfmt-style_edition: 2024 | ||
enum A { | ||
B { | ||
a: usize, | ||
b: usize, | ||
c: usize, | ||
d: usize, | ||
}, | ||
|
||
#[multiline_macro_attribute( | ||
very_very_long_option1, | ||
very_very_long_option2, | ||
very_very_long_option3 | ||
)] | ||
C { | ||
a: usize, | ||
}, | ||
|
||
#[attr_with_expression1(x = ']')] | ||
D1 { | ||
a: usize, | ||
}, | ||
|
||
#[attr_with_expression2(x = vec![])] | ||
D2 { | ||
a: usize, | ||
}, | ||
|
||
#[attr_with_expression3(x = "]")] | ||
D3 { | ||
a: usize, | ||
}, | ||
|
||
#[attr_with_expression4(x = "\"]")] | ||
D4 { | ||
a: usize, | ||
}, | ||
|
||
#[attr1] | ||
#[attr2] | ||
D5 { | ||
a: usize, | ||
}, | ||
} |