diff options
Diffstat (limited to 'src/item.rs')
-rw-r--r-- | src/item.rs | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/src/item.rs b/src/item.rs index d5c3b277..10479ab4 100644 --- a/src/item.rs +++ b/src/item.rs @@ -380,7 +380,11 @@ impl Item { | Item::Macro(ItemMacro { attrs, .. }) | Item::Macro2(ItemMacro2 { attrs, .. }) => mem::replace(attrs, new), Item::Verbatim(_) => Vec::new(), - Item::__TestExhaustive(_) => unreachable!(), + + #[cfg(test)] + Item::__TestExhaustive(_) => unimplemented!(), + #[cfg(not(test))] + _ => unreachable!(), } } } @@ -982,6 +986,7 @@ pub mod parsing { use std::iter::{self, FromIterator}; crate::custom_keyword!(existential); + crate::custom_keyword!(macro_rules); #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Item { @@ -1026,24 +1031,31 @@ pub mod parsing { let static_token = input.parse()?; let mutability = input.parse()?; let ident = input.parse()?; - let colon_token = input.parse()?; - let ty = input.parse()?; - if input.peek(Token![;]) { + if input.peek(Token![=]) { + input.parse::<Token![=]>()?; + input.parse::<Expr>()?; input.parse::<Token![;]>()?; Ok(Item::Verbatim(verbatim::between(begin, input))) } else { - Ok(Item::Static(ItemStatic { - attrs: Vec::new(), - vis, - static_token, - mutability, - ident, - colon_token, - ty, - eq_token: input.parse()?, - expr: input.parse()?, - semi_token: input.parse()?, - })) + let colon_token = input.parse()?; + let ty = input.parse()?; + if input.peek(Token![;]) { + input.parse::<Token![;]>()?; + Ok(Item::Verbatim(verbatim::between(begin, input))) + } else { + Ok(Item::Static(ItemStatic { + attrs: Vec::new(), + vis, + static_token, + mutability, + ident, + colon_token, + ty, + eq_token: input.parse()?, + expr: input.parse()?, + semi_token: input.parse()?, + })) + } } } else if lookahead.peek(Token![const]) { ahead.parse::<Token![const]>()?; @@ -1142,6 +1154,10 @@ pub mod parsing { || lookahead.peek(Token![::])) { input.parse().map(Item::Macro) + } else if ahead.peek(macro_rules) { + input.advance_to(&ahead); + input.parse::<ItemMacro>()?; + Ok(Item::Verbatim(verbatim::between(begin, input))) } else { Err(lookahead.error()) }?; @@ -1164,7 +1180,6 @@ pub mod parsing { semi_token: Token![;], } - #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for FlexibleItemType { fn parse(input: ParseStream) -> Result<Self> { let vis: Visibility = input.parse()?; @@ -1176,14 +1191,14 @@ pub mod parsing { let mut bounds = Punctuated::new(); if colon_token.is_some() { loop { - bounds.push_value(input.parse::<TypeParamBound>()?); if input.peek(Token![where]) || input.peek(Token![=]) || input.peek(Token![;]) { break; } - bounds.push_punct(input.parse::<Token![+]>()?); + bounds.push_value(input.parse::<TypeParamBound>()?); if input.peek(Token![where]) || input.peek(Token![=]) || input.peek(Token![;]) { break; } + bounds.push_punct(input.parse::<Token![+]>()?); } } generics.where_clause = input.parse()?; @@ -1497,11 +1512,11 @@ pub mod parsing { abi, fn_token, ident, + generics, paren_token, inputs, - output, variadic, - generics, + output, }) } } @@ -1787,7 +1802,11 @@ pub mod parsing { ForeignItem::Type(item) => &mut item.attrs, ForeignItem::Macro(item) => &mut item.attrs, ForeignItem::Verbatim(_) => return Ok(item), - ForeignItem::__TestExhaustive(_) => unreachable!(), + + #[cfg(test)] + ForeignItem::__TestExhaustive(_) => unimplemented!(), + #[cfg(not(test))] + _ => unreachable!(), }; attrs.extend(item_attrs.drain(..)); *item_attrs = attrs; @@ -2265,7 +2284,12 @@ pub mod parsing { TraitItem::Method(item) => &mut item.attrs, TraitItem::Type(item) => &mut item.attrs, TraitItem::Macro(item) => &mut item.attrs, - TraitItem::Verbatim(_) | TraitItem::__TestExhaustive(_) => unreachable!(), + TraitItem::Verbatim(_) => unreachable!(), + + #[cfg(test)] + TraitItem::__TestExhaustive(_) => unimplemented!(), + #[cfg(not(test))] + _ => unreachable!(), }; attrs.extend(item_attrs.drain(..)); *item_attrs = attrs; @@ -2596,7 +2620,11 @@ pub mod parsing { ImplItem::Type(item) => &mut item.attrs, ImplItem::Macro(item) => &mut item.attrs, ImplItem::Verbatim(_) => return Ok(item), - ImplItem::__TestExhaustive(_) => unreachable!(), + + #[cfg(test)] + ImplItem::__TestExhaustive(_) => unimplemented!(), + #[cfg(not(test))] + _ => unreachable!(), }; attrs.extend(item_attrs.drain(..)); *item_attrs = attrs; |