@@ -1544,55 +1544,48 @@ pub enum ClosureBinder {
1544
1544
#[ derive( Clone , Encodable , Decodable , Debug ) ]
1545
1545
pub struct MacCall {
1546
1546
pub path : Path ,
1547
- pub args : P < MacArgs > ,
1547
+ pub args : P < DelimArgs > ,
1548
1548
pub prior_type_ascription : Option < ( Span , bool ) > ,
1549
1549
}
1550
1550
1551
1551
impl MacCall {
1552
1552
pub fn span ( & self ) -> Span {
1553
- self . path . span . to ( self . args . span ( ) . unwrap_or ( self . path . span ) )
1553
+ self . path . span . to ( self . args . dspan . entire ( ) )
1554
1554
}
1555
1555
}
1556
1556
1557
- /// Arguments passed to an attribute or a function-like macro.
1557
+ /// Arguments passed to an attribute macro.
1558
1558
#[ derive( Clone , Encodable , Decodable , Debug ) ]
1559
- pub enum MacArgs {
1560
- /// No arguments - `#[attr]`.
1559
+ pub enum AttrArgs {
1560
+ /// No arguments: `#[attr]`.
1561
1561
Empty ,
1562
- /// Delimited arguments - `#[attr()/[]/{}]` or `mac!()/[]/{} `.
1563
- Delimited ( DelimSpan , MacDelimiter , TokenStream ) ,
1564
- /// Arguments of a key-value attribute - `#[attr = "value"]`.
1562
+ /// Delimited arguments: `#[attr()/[]/{}]`.
1563
+ Delimited ( DelimArgs ) ,
1564
+ /// Arguments of a key-value attribute: `#[attr = "value"]`.
1565
1565
Eq (
1566
1566
/// Span of the `=` token.
1567
1567
Span ,
1568
1568
/// The "value".
1569
- MacArgsEq ,
1569
+ AttrArgsEq ,
1570
1570
) ,
1571
1571
}
1572
1572
1573
- // The RHS of a `MacArgs ::Eq` starts out as an expression. Once macro expansion
1574
- // is completed, all cases end up either as a literal, which is the form used
1575
- // after lowering to HIR, or as an error.
1573
+ // The RHS of an `AttrArgs ::Eq` starts out as an expression. Once macro
1574
+ // expansion is completed, all cases end up either as a literal, which is the
1575
+ // form used after lowering to HIR, or as an error.
1576
1576
#[ derive( Clone , Encodable , Decodable , Debug ) ]
1577
- pub enum MacArgsEq {
1577
+ pub enum AttrArgsEq {
1578
1578
Ast ( P < Expr > ) ,
1579
1579
Hir ( Lit ) ,
1580
1580
}
1581
1581
1582
- impl MacArgs {
1583
- pub fn delim ( & self ) -> Option < Delimiter > {
1584
- match self {
1585
- MacArgs :: Delimited ( _, delim, _) => Some ( delim. to_token ( ) ) ,
1586
- MacArgs :: Empty | MacArgs :: Eq ( ..) => None ,
1587
- }
1588
- }
1589
-
1582
+ impl AttrArgs {
1590
1583
pub fn span ( & self ) -> Option < Span > {
1591
1584
match self {
1592
- MacArgs :: Empty => None ,
1593
- MacArgs :: Delimited ( dspan , .. ) => Some ( dspan. entire ( ) ) ,
1594
- MacArgs :: Eq ( eq_span, MacArgsEq :: Ast ( expr) ) => Some ( eq_span. to ( expr. span ) ) ,
1595
- MacArgs :: Eq ( _, MacArgsEq :: Hir ( lit) ) => {
1585
+ AttrArgs :: Empty => None ,
1586
+ AttrArgs :: Delimited ( args ) => Some ( args . dspan . entire ( ) ) ,
1587
+ AttrArgs :: Eq ( eq_span, AttrArgsEq :: Ast ( expr) ) => Some ( eq_span. to ( expr. span ) ) ,
1588
+ AttrArgs :: Eq ( _, AttrArgsEq :: Hir ( lit) ) => {
1596
1589
unreachable ! ( "in literal form when getting span: {:?}" , lit) ;
1597
1590
}
1598
1591
}
@@ -1602,46 +1595,64 @@ impl MacArgs {
1602
1595
/// Proc macros see these tokens, for example.
1603
1596
pub fn inner_tokens ( & self ) -> TokenStream {
1604
1597
match self {
1605
- MacArgs :: Empty => TokenStream :: default ( ) ,
1606
- MacArgs :: Delimited ( .. , tokens ) => tokens. clone ( ) ,
1607
- MacArgs :: Eq ( _, MacArgsEq :: Ast ( expr) ) => TokenStream :: from_ast ( expr) ,
1608
- MacArgs :: Eq ( _, MacArgsEq :: Hir ( lit) ) => {
1598
+ AttrArgs :: Empty => TokenStream :: default ( ) ,
1599
+ AttrArgs :: Delimited ( args ) => args . tokens . clone ( ) ,
1600
+ AttrArgs :: Eq ( _, AttrArgsEq :: Ast ( expr) ) => TokenStream :: from_ast ( expr) ,
1601
+ AttrArgs :: Eq ( _, AttrArgsEq :: Hir ( lit) ) => {
1609
1602
unreachable ! ( "in literal form when getting inner tokens: {:?}" , lit)
1610
1603
}
1611
1604
}
1612
1605
}
1613
-
1614
- /// Whether a macro with these arguments needs a semicolon
1615
- /// when used as a standalone item or statement.
1616
- pub fn need_semicolon ( & self ) -> bool {
1617
- !matches ! ( self , MacArgs :: Delimited ( _, MacDelimiter :: Brace , _) )
1618
- }
1619
1606
}
1620
1607
1621
- impl < CTX > HashStable < CTX > for MacArgs
1608
+ impl < CTX > HashStable < CTX > for AttrArgs
1622
1609
where
1623
1610
CTX : crate :: HashStableContext ,
1624
1611
{
1625
1612
fn hash_stable ( & self , ctx : & mut CTX , hasher : & mut StableHasher ) {
1626
1613
mem:: discriminant ( self ) . hash_stable ( ctx, hasher) ;
1627
1614
match self {
1628
- MacArgs :: Empty => { }
1629
- MacArgs :: Delimited ( dspan, delim, tokens) => {
1630
- dspan. hash_stable ( ctx, hasher) ;
1631
- delim. hash_stable ( ctx, hasher) ;
1632
- tokens. hash_stable ( ctx, hasher) ;
1633
- }
1634
- MacArgs :: Eq ( _eq_span, MacArgsEq :: Ast ( expr) ) => {
1615
+ AttrArgs :: Empty => { }
1616
+ AttrArgs :: Delimited ( args) => args. hash_stable ( ctx, hasher) ,
1617
+ AttrArgs :: Eq ( _eq_span, AttrArgsEq :: Ast ( expr) ) => {
1635
1618
unreachable ! ( "hash_stable {:?}" , expr) ;
1636
1619
}
1637
- MacArgs :: Eq ( eq_span, MacArgsEq :: Hir ( lit) ) => {
1620
+ AttrArgs :: Eq ( eq_span, AttrArgsEq :: Hir ( lit) ) => {
1638
1621
eq_span. hash_stable ( ctx, hasher) ;
1639
1622
lit. hash_stable ( ctx, hasher) ;
1640
1623
}
1641
1624
}
1642
1625
}
1643
1626
}
1644
1627
1628
+ /// Delimited arguments, as used in `#[attr()/[]/{}]` or `mac!()/[]/{}`.
1629
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
1630
+ pub struct DelimArgs {
1631
+ pub dspan : DelimSpan ,
1632
+ pub delim : MacDelimiter ,
1633
+ pub tokens : TokenStream ,
1634
+ }
1635
+
1636
+ impl DelimArgs {
1637
+ /// Whether a macro with these arguments needs a semicolon
1638
+ /// when used as a standalone item or statement.
1639
+ pub fn need_semicolon ( & self ) -> bool {
1640
+ !matches ! ( self , DelimArgs { delim: MacDelimiter :: Brace , .. } )
1641
+ }
1642
+ }
1643
+
1644
+ impl < CTX > HashStable < CTX > for DelimArgs
1645
+ where
1646
+ CTX : crate :: HashStableContext ,
1647
+ {
1648
+ fn hash_stable ( & self , ctx : & mut CTX , hasher : & mut StableHasher ) {
1649
+ let DelimArgs { dspan, delim, tokens } = self ;
1650
+ dspan. hash_stable ( ctx, hasher) ;
1651
+ delim. hash_stable ( ctx, hasher) ;
1652
+ tokens. hash_stable ( ctx, hasher) ;
1653
+ }
1654
+ }
1655
+
1645
1656
#[ derive( Copy , Clone , PartialEq , Eq , Encodable , Decodable , Debug , HashStable_Generic ) ]
1646
1657
pub enum MacDelimiter {
1647
1658
Parenthesis ,
@@ -1671,7 +1682,7 @@ impl MacDelimiter {
1671
1682
/// Represents a macro definition.
1672
1683
#[ derive( Clone , Encodable , Decodable , Debug , HashStable_Generic ) ]
1673
1684
pub struct MacroDef {
1674
- pub body : P < MacArgs > ,
1685
+ pub body : P < DelimArgs > ,
1675
1686
/// `true` if macro was defined with `macro_rules`.
1676
1687
pub macro_rules : bool ,
1677
1688
}
@@ -2534,7 +2545,7 @@ impl<D: Decoder> Decodable<D> for AttrId {
2534
2545
#[ derive( Clone , Encodable , Decodable , Debug , HashStable_Generic ) ]
2535
2546
pub struct AttrItem {
2536
2547
pub path : Path ,
2537
- pub args : MacArgs ,
2548
+ pub args : AttrArgs ,
2538
2549
pub tokens : Option < LazyAttrTokenStream > ,
2539
2550
}
2540
2551
0 commit comments