diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-12-18 21:02:14 +0100 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-12-18 21:02:14 +0100 |
| commit | 88d5f7f4ce72e3489193fb41e687c53809b5c6bd (patch) | |
| tree | 7db76b11fa1b3b9621793929691bac32d86d0116 /compiler/rustc_macros/src | |
| parent | b4d739ef1285bc983383ec726314d9455f6bfb77 (diff) | |
| download | rust-88d5f7f4ce72e3489193fb41e687c53809b5c6bd.tar.gz rust-88d5f7f4ce72e3489193fb41e687c53809b5c6bd.zip | |
Make `#[custom_encodable]` an attribute for `newtype_index`
Makes the syntax a little more rusty.
Diffstat (limited to 'compiler/rustc_macros/src')
| -rw-r--r-- | compiler/rustc_macros/src/newtype.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/compiler/rustc_macros/src/newtype.rs b/compiler/rustc_macros/src/newtype.rs index 46f5ead5942..2e28e9fb49d 100644 --- a/compiler/rustc_macros/src/newtype.rs +++ b/compiler/rustc_macros/src/newtype.rs @@ -6,7 +6,6 @@ use syn::*; mod kw { syn::custom_keyword!(DEBUG_FORMAT); syn::custom_keyword!(MAX); - syn::custom_keyword!(ENCODABLE); syn::custom_keyword!(custom); syn::custom_keyword!(ORD_IMPL); } @@ -27,7 +26,7 @@ struct Newtype(TokenStream); impl Parse for Newtype { fn parse(input: ParseStream<'_>) -> Result<Self> { - let attrs = input.call(Attribute::parse_outer)?; + let mut attrs = input.call(Attribute::parse_outer)?; let vis: Visibility = input.parse()?; input.parse::<Token![struct]>()?; let name: Ident = input.parse()?; @@ -51,6 +50,17 @@ impl Parse for Newtype { Ok(()) }; + attrs.retain(|attr| match attr.path.get_ident() { + Some(ident) => match &*ident.to_string() { + "custom_encodable" => { + encodable = false; + false + } + _ => true, + }, + _ => true, + }); + if body.lookahead1().peek(Token![..]) { body.parse::<Token![..]>()?; } else { @@ -81,14 +91,6 @@ impl Parse for Newtype { } continue; } - if body.lookahead1().peek(kw::ENCODABLE) { - body.parse::<kw::ENCODABLE>()?; - body.parse::<Token![=]>()?; - body.parse::<kw::custom>()?; - try_comma()?; - encodable = false; - continue; - } if body.lookahead1().peek(kw::ORD_IMPL) { body.parse::<kw::ORD_IMPL>()?; body.parse::<Token![=]>()?; |
