1919//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
2020
2121use std:: borrow:: Cow ;
22- use std:: { cmp, fmt, mem } ;
22+ use std:: { cmp, fmt} ;
2323
2424pub use GenericArgs :: * ;
2525pub use UnsafeSource :: * ;
@@ -1684,32 +1684,20 @@ pub enum AttrArgs {
16841684 /// Delimited arguments: `#[attr()/[]/{}]`.
16851685 Delimited ( DelimArgs ) ,
16861686 /// Arguments of a key-value attribute: `#[attr = "value"]`.
1687- Eq (
1687+ Eq {
16881688 /// Span of the `=` token.
1689- Span ,
1689+ eq_span : Span ,
16901690 /// The "value".
1691- AttrArgsEq ,
1692- ) ,
1693- }
1694-
1695- // The RHS of an `AttrArgs::Eq` starts out as an expression. Once macro
1696- // expansion is completed, all cases end up either as a meta item literal,
1697- // which is the form used after lowering to HIR, or as an error.
1698- #[ derive( Clone , Encodable , Decodable , Debug ) ]
1699- pub enum AttrArgsEq {
1700- Ast ( P < Expr > ) ,
1701- Hir ( MetaItemLit ) ,
1691+ value : P < Expr > ,
1692+ } ,
17021693}
17031694
17041695impl AttrArgs {
17051696 pub fn span ( & self ) -> Option < Span > {
17061697 match self {
17071698 AttrArgs :: Empty => None ,
17081699 AttrArgs :: Delimited ( args) => Some ( args. dspan . entire ( ) ) ,
1709- AttrArgs :: Eq ( eq_span, AttrArgsEq :: Ast ( expr) ) => Some ( eq_span. to ( expr. span ) ) ,
1710- AttrArgs :: Eq ( _, AttrArgsEq :: Hir ( lit) ) => {
1711- unreachable ! ( "in literal form when getting span: {:?}" , lit) ;
1712- }
1700+ AttrArgs :: Eq ( eq_span, expr) => Some ( eq_span. to ( expr. span ) ) ,
17131701 }
17141702 }
17151703
@@ -1719,30 +1707,7 @@ impl AttrArgs {
17191707 match self {
17201708 AttrArgs :: Empty => TokenStream :: default ( ) ,
17211709 AttrArgs :: Delimited ( args) => args. tokens . clone ( ) ,
1722- AttrArgs :: Eq ( _, AttrArgsEq :: Ast ( expr) ) => TokenStream :: from_ast ( expr) ,
1723- AttrArgs :: Eq ( _, AttrArgsEq :: Hir ( lit) ) => {
1724- unreachable ! ( "in literal form when getting inner tokens: {:?}" , lit)
1725- }
1726- }
1727- }
1728- }
1729-
1730- impl < CTX > HashStable < CTX > for AttrArgs
1731- where
1732- CTX : crate :: HashStableContext ,
1733- {
1734- fn hash_stable ( & self , ctx : & mut CTX , hasher : & mut StableHasher ) {
1735- mem:: discriminant ( self ) . hash_stable ( ctx, hasher) ;
1736- match self {
1737- AttrArgs :: Empty => { }
1738- AttrArgs :: Delimited ( args) => args. hash_stable ( ctx, hasher) ,
1739- AttrArgs :: Eq ( _eq_span, AttrArgsEq :: Ast ( expr) ) => {
1740- unreachable ! ( "hash_stable {:?}" , expr) ;
1741- }
1742- AttrArgs :: Eq ( eq_span, AttrArgsEq :: Hir ( lit) ) => {
1743- eq_span. hash_stable ( ctx, hasher) ;
1744- lit. hash_stable ( ctx, hasher) ;
1745- }
1710+ AttrArgs :: Eq ( _, expr) => TokenStream :: from_ast ( expr) ,
17461711 }
17471712 }
17481713}
@@ -2892,7 +2857,7 @@ pub enum AttrStyle {
28922857}
28932858
28942859/// A list of attributes.
2895- pub type AttrVec = ThinVec < Attribute > ;
2860+ pub type AttrVec < A = Attribute > = ThinVec < A > ;
28962861
28972862/// A syntax-level representation of an attribute.
28982863#[ derive( Clone , Encodable , Decodable , Debug ) ]
@@ -2937,7 +2902,7 @@ impl NormalAttr {
29372902 }
29382903}
29392904
2940- #[ derive( Clone , Encodable , Decodable , Debug , HashStable_Generic ) ]
2905+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
29412906pub struct AttrItem {
29422907 pub unsafety : Safety ,
29432908 pub path : Path ,
@@ -3078,8 +3043,8 @@ impl VariantData {
30783043
30793044/// An item definition.
30803045#[ derive( Clone , Encodable , Decodable , Debug ) ]
3081- pub struct Item < K = ItemKind > {
3082- pub attrs : AttrVec ,
3046+ pub struct Item < K = ItemKind , A = Attribute > {
3047+ pub attrs : AttrVec < A > ,
30833048 pub id : NodeId ,
30843049 pub span : Span ,
30853050 pub vis : Visibility ,
0 commit comments