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