Skip to content

Commit 9b42f94

Browse files
author
Ted Driggs
committed
Use conventional meta-item syntax for attributes
Using the conventional form for attributes, which is compatible with rustfmt and syn's meta-item parsing. This change is breaking and substantial, but the necessary edits are largely mechanical. With meta-items, it becomes possible to offload attribute parsing and validation to `darling`. This offload fixes rustwasm#2874, as `darling` will automatically generate errors for unexpected meta-item names. This also makes it easier for people who are new to the codebase to understand how to add new options. This commit does not build: It changes the macro parser, but does not update the usage of the macro.
1 parent e8ea739 commit 9b42f94

File tree

8 files changed

+554
-578
lines changed

8 files changed

+554
-578
lines changed

crates/backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extra-traits = ["syn/extra-traits"]
1717

1818
[dependencies]
1919
bumpalo = "3.0.0"
20+
darling = "0.14.1"
2021
lazy_static = "1.0.2"
2122
log = "0.4"
2223
proc-macro2 = "1.0"

crates/backend/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ impl From<Error> for Diagnostic {
9898
}
9999
}
100100

101+
impl From<darling::Error> for Diagnostic {
102+
fn from(err: darling::Error) -> Self {
103+
Self::from(Error::from(err))
104+
}
105+
}
106+
101107
fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
102108
let mut t = TokenStream::new();
103109
node.to_tokens(&mut t);

crates/macro-support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extra-traits = ["syn/extra-traits"]
1717
strict-macro = []
1818

1919
[dependencies]
20+
darling = "0.14.1"
2021
syn = { version = '1.0.67', features = ['visit', 'full'] }
2122
quote = '1.0'
2223
proc-macro2 = "1.0"

0 commit comments

Comments
 (0)