@@ -1520,6 +1520,7 @@ impl<'a> Parser<'a> {
1520
1520
fn parse_restriction (
1521
1521
& mut self ,
1522
1522
kw : ExpKeywordPair ,
1523
+ feature_gate : Option < Symbol > ,
1523
1524
action : & ' static str ,
1524
1525
description : & ' static str ,
1525
1526
fbt : FollowedByType ,
@@ -1531,6 +1532,13 @@ impl<'a> Parser<'a> {
1531
1532
return Ok ( Restriction :: implied ( ) . with_span ( self . token . span . shrink_to_lo ( ) ) ) ;
1532
1533
}
1533
1534
1535
+ let gate = |span| {
1536
+ if let Some ( feature_gate) = feature_gate {
1537
+ self . psess . gated_spans . gate ( feature_gate, span) ;
1538
+ }
1539
+ span
1540
+ } ;
1541
+
1534
1542
let lo = self . prev_token . span ;
1535
1543
1536
1544
if self . check ( exp ! ( OpenParen ) ) {
@@ -1545,16 +1553,16 @@ impl<'a> Parser<'a> {
1545
1553
let path = self . parse_path ( PathStyle :: Mod ) ?; // `path`
1546
1554
self . expect ( exp ! ( CloseParen ) ) ?; // `)`
1547
1555
return Ok ( Restriction :: restricted ( P ( path) , ast:: DUMMY_NODE_ID , false )
1548
- . with_span ( lo. to ( self . prev_token . span ) ) ) ;
1556
+ . with_span ( gate ( lo. to ( self . prev_token . span ) ) ) ) ;
1549
1557
} else if self . look_ahead ( 2 , |t| t == & TokenKind :: CloseParen )
1550
1558
&& self . is_keyword_ahead ( 1 , & [ kw:: Crate , kw:: Super , kw:: SelfLower ] )
1551
1559
{
1552
1560
// Parse `kw(crate)`, `kw(self)`, or `kw(super)`.
1553
1561
self . bump ( ) ; // `(`
1554
1562
let path = self . parse_path ( PathStyle :: Mod ) ?; // `crate`/`super`/`self`
1555
1563
self . expect ( exp ! ( CloseParen ) ) ?; // `)`
1556
- return Ok ( Restriction :: restricted ( P ( path) , ast:: DUMMY_NODE_ID , false )
1557
- . with_span ( lo. to ( self . prev_token . span ) ) ) ;
1564
+ return Ok ( Restriction :: restricted ( P ( path) , ast:: DUMMY_NODE_ID , true )
1565
+ . with_span ( gate ( lo. to ( self . prev_token . span ) ) ) ) ;
1558
1566
} else if let FollowedByType :: No = fbt {
1559
1567
// Provide this diagnostic if a type cannot follow;
1560
1568
// in particular, if this is not a tuple struct.
@@ -1563,7 +1571,7 @@ impl<'a> Parser<'a> {
1563
1571
}
1564
1572
}
1565
1573
1566
- Ok ( Restriction :: unrestricted ( ) . with_span ( lo ) )
1574
+ Ok ( Restriction :: unrestricted ( ) . with_span ( gate ( lo ) ) )
1567
1575
}
1568
1576
1569
1577
/// Recovery for e.g. `kw(something) fn ...` or `struct X { kw(something) y: Z }`
0 commit comments