@@ -269,10 +269,9 @@ import Text.Read (readMaybe)
269
269
-- * 'FIELD' for field access expressions (which bind less tightly than ' .' for method calls)
270
270
-- * 'VIS' for adjusting the precedence of 'pub' compared to other visbility modifiers (see ' vis' )
271
271
-- * 'PATH' boosts the precedences of paths in types and expressions
272
- -- * 'DOLLAR' is for a single '$' token not in sequence expression
273
272
-- * 'WHERE' is for non-empty where clauses
274
273
--
275
- %nonassoc FIELD VIS PATH DOLLAR WHERE
274
+ %nonassoc FIELD VIS PATH WHERE
276
275
277
276
-- These are postfix operators.
278
277
%nonassoc '?' '.'
@@ -1190,10 +1189,14 @@ generics :: { Generics Span }
1190
1189
1191
1190
-- TODO: Attributes? The AST has them, so the parser should produce them
1192
1191
ty_param :: { TyParam Span }
1193
- : ident { TyParam [] (unspan $1) [] Nothing (spanOf $1) }
1194
- | ident ' :' sep_by1T(ty_param_bound_mod,' +' ) { TyParam [] (unspan $1) (toList $3) Nothing ($1 # $3) }
1195
- | ident ' =' ty { TyParam [] (unspan $1) [] (Just $>) (spanOf $1) }
1196
- | ident ' :' sep_by1T(ty_param_bound_mod,' +' ) ' =' ty { TyParam [] (unspan $1) (toList $3) (Just $>) ($1 # $>) }
1192
+ : ident { TyParam [] (unspan $1) [] Nothing (spanOf $1) }
1193
+ | inner_attrs ident { TyParam (toList $1) (unspan $2) [] Nothing ($1 # $>) }
1194
+ | ident ' :' sep_by1T(ty_param_bound_mod,' +' ) { TyParam [] (unspan $1) (toList $3) Nothing ($1 # $>) }
1195
+ | inner_attrs ident ' :' sep_by1T(ty_param_bound_mod,' +' ) { TyParam (toList $1) (unspan $2) (toList $4) Nothing ($1 # $>) }
1196
+ | ident ' =' ty { TyParam [] (unspan $1) [] (Just $>) (spanOf $1) }
1197
+ | inner_attrs ident ' =' ty { TyParam (toList $1) (unspan $2) [] (Just $>) ($1 # $>) }
1198
+ | ident ' :' sep_by1T(ty_param_bound_mod,' +' ) ' =' ty { TyParam [] (unspan $1) (toList $3) (Just $>) ($1 # $>) }
1199
+ | inner_attrs ident ' :' sep_by1T(ty_param_bound_mod,' +' ) ' =' ty { TyParam (toList $1) (unspan $2) (toList $4) (Just $>) ($1 # $>) }
1197
1200
1198
1201
stmt_item :: { Item Span }
1199
1202
: static ident ' :' ty ' =' expr ' ;' { Item (unspan $2) [] (Static $4 Immutable $6) InheritedV ($1 # $>) }
@@ -1203,10 +1206,10 @@ stmt_item :: { Item Span }
1203
1206
| use view_path ' ;' { Item "" [] (Use $2) InheritedV ($1 # $>) }
1204
1207
| extern crate ident ' ;' { Item (unspan $3) [] (ExternCrate Nothing) InheritedV ($1 # $>) }
1205
1208
| extern crate ident as ident ' ;' { Item (unspan $5) [] (ExternCrate (Just (unspan $3))) InheritedV ($1 # $>) }
1206
- | const safety fn ident generics fn_decl where_clause inner_attrs_block
1207
- { Item (unspan $4) (fst $>) (Fn $6 $2 Const Rust $5{ whereClause = $7 } (snd $>)) InheritedV ($1 # snd $>) }
1209
+ | const safety fn ident generics fn_decl where_clause inner_attrs_block
1210
+ { Item (unspan $4) (fst $>) (Fn $6 (unspan $2) Const Rust $5{ whereClause = $7 } (snd $>)) InheritedV ($1 # snd $>) }
1208
1211
| unsafe ext_abi fn ident generics fn_decl where_clause inner_attrs_block
1209
- { Item (unspan $4) (fst $>) (Fn $6 Unsafe NotConst $2 $5{ whereClause = $7 } (snd $>)) InheritedV ($1 # snd $>) }
1212
+ { Item (unspan $4) (fst $>) (Fn $6 Unsafe NotConst (unspan $2) $5{ whereClause = $7 } (snd $>)) InheritedV ($1 # snd $>) }
1210
1213
| extern abi fn ident generics fn_decl where_clause inner_attrs_block
1211
1214
{ Item (unspan $4) (fst $>) (Fn $6 Normal NotConst $2 $5{ whereClause = $7 } (snd $>)) InheritedV ($1 # snd $>) }
1212
1215
| fn ident generics fn_decl where_clause inner_attrs_block
@@ -1224,14 +1227,10 @@ stmt_item :: { Item Span }
1224
1227
| item_trait { $1 }
1225
1228
1226
1229
item_trait :: { Item Span }
1227
- : safety_trait ident generics ' :' sep_by1T(ty_param_bound,' +' ) where_clause ' {' many(trait_item) ' }'
1228
- { Item (unspan $2) [] (Trait (unspan $1) $3{ whereClause = $6 } (toList $5) $8) InheritedV ($1 # $>) }
1229
- | safety_trait ident generics where_clause ' {' many(trait_item) ' }'
1230
- { Item (unspan $2) [] (Trait (unspan $1) $3{ whereClause = $4 } [] $6) InheritedV ($1 # $>) }
1231
-
1232
- safety_trait :: { Spanned Unsafety }
1233
- : trait { Spanned Normal (spanOf $1) }
1234
- | unsafe trait { Spanned Unsafe ($1 # $2) }
1230
+ : safety trait ident generics ' :' sep_by1T(ty_param_bound,' +' ) where_clause ' {' many(trait_item) ' }'
1231
+ { Item (unspan $3) [] (Trait (unspan $1) $4{ whereClause = $7 } (toList $6) $9) InheritedV ($1 # $2 # $>) }
1232
+ | safety trait ident generics where_clause ' {' many(trait_item) ' }'
1233
+ { Item (unspan $3) [] (Trait (unspan $1) $4{ whereClause = $5 } [] $7) InheritedV ($1 # $2 # $>) }
1235
1234
1236
1235
struct_decl_args :: { (WhereClause Span, VariantData Span) }
1237
1236
: where_clause ' ;' { ($1, UnitD ($1 # $>)) }
@@ -1268,62 +1267,50 @@ where_predicate :: { WherePredicate Span }
1268
1267
1269
1268
1270
1269
item_impl :: { Item Span }
1271
- : safety_impl generics ty_prim where_clause ' {' impl_items ' }'
1272
- { Item (mkIdent "") (fst $6 ) (Impl (unspan $1) Positive $2 { whereClause = $4 } Nothing $3 (snd $6 )) InheritedV ($1 # $>) }
1273
- | safety_impl generics ' (' ty_no_plus ' )' where_clause ' {' impl_items ' }'
1274
- { Item (mkIdent "") (fst $8 ) (Impl (unspan $1) Positive $2 { whereClause = $6 } Nothing (ParenTy $4 ($3 # $5 )) (snd $8 )) InheritedV ($1 # $>) }
1275
- | safety_impl generics ' !' trait_ref for ty where_clause ' {' impl_items ' }'
1276
- { Item (mkIdent "") (fst $9 ) (Impl (unspan $1) Negative $2 { whereClause = $7 } (Just $4 ) $6 (snd $9 )) InheritedV ($1 # $>) }
1277
- | safety_impl generics trait_ref for ty where_clause ' {' impl_items ' }'
1278
- { Item (mkIdent "") (fst $8 ) (Impl (unspan $1) Positive $2 { whereClause = $6 } (Just $3 ) $5 (snd $8 )) InheritedV ($1 # $>) }
1279
- | safety_impl generics trait_ref for ' ..' ' {' ' }'
1280
- {% case $2 of
1281
- Generics [] [] _ _ -> pure $ Item (mkIdent "") [] (DefaultImpl (unspan $1) $3 ) InheritedV ($1 # $>)
1270
+ : safety impl generics ty_prim where_clause ' {' impl_items ' }'
1271
+ { Item (mkIdent "") (fst $7 ) (Impl (unspan $1) Positive $3 { whereClause = $5 } Nothing $4 (snd $7 )) InheritedV ($1 # $2 # $>) }
1272
+ | safety impl generics ' (' ty_no_plus ' )' where_clause ' {' impl_items ' }'
1273
+ { Item (mkIdent "") (fst $9 ) (Impl (unspan $1) Positive $3 { whereClause = $7 } Nothing (ParenTy $5 ($4 # $6 )) (snd $9 )) InheritedV ($1 # $2 # $>) }
1274
+ | safety impl generics ' !' trait_ref for ty where_clause ' {' impl_items ' }'
1275
+ { Item (mkIdent "") (fst $10 ) (Impl (unspan $1) Negative $3 { whereClause = $8 } (Just $5 ) $7 (snd $10 )) InheritedV ($1 # $2 # $>) }
1276
+ | safety impl generics trait_ref for ty where_clause ' {' impl_items ' }'
1277
+ { Item (mkIdent "") (fst $9 ) (Impl (unspan $1) Positive $3 { whereClause = $7 } (Just $4 ) $6 (snd $9 )) InheritedV ($1 # $2 # $>) }
1278
+ | safety impl generics trait_ref for ' ..' ' {' ' }'
1279
+ {% case $3 of
1280
+ Generics [] [] _ _ -> pure $ Item (mkIdent "") [] (DefaultImpl (unspan $1) $4 ) InheritedV ($1 # $2 # $>)
1282
1281
_ -> fail "non-empty generics are no allowed on default implementations"
1283
1282
}
1284
1283
1285
- safety_impl :: { Spanned Unsafety }
1286
- : impl { Spanned Normal (spanOf $1) }
1287
- | unsafe impl { Spanned Unsafe ($1 # $2) }
1288
-
1289
1284
impl_items :: { ([Attribute Span], [ImplItem Span]) }
1290
1285
: many(impl_item) { ([], $1) }
1291
1286
| inner_attrs many(impl_item) { (toList $1, $2) }
1292
1287
1293
1288
impl_item :: { ImplItem Span }
1294
1289
: ntImplItem { $1 }
1295
- | many(outer_attribute) vis def type ident ' =' ty ' ;' { ImplItem (unspan $5) (unspan $2) $3 $1 (TypeI $7) ($1 # $2 # $>) }
1296
- | many(outer_attribute) vis def const ident ' :' ty ' =' expr ' ;' { ImplItem (unspan $5) (unspan $2) $3 $1 (ConstI $7 $9) ($1 # $2 # $>) }
1297
- | many(outer_attribute) vis def mod_mac { ImplItem (mkIdent "") (unspan $2) $3 $1 (MacroI $4) ($1 # $2 # $>) }
1290
+ | many(outer_attribute) vis def type ident ' =' ty ' ;' { ImplItem (unspan $5) (unspan $2) (unspan $3) $1 (TypeI $7) ($1 # $2 # $>) }
1291
+ | many(outer_attribute) vis def const ident ' :' ty ' =' expr ' ;' { ImplItem (unspan $5) (unspan $2) (unspan $3) $1 (ConstI $7 $9) ($1 # $2 # $>) }
1292
+ | many(outer_attribute) vis def mod_mac { ImplItem (mkIdent "") (unspan $2) (unspan $3) $1 (MacroI $4) ($1 # $2 # $>) }
1298
1293
| many(outer_attribute) vis def const safety fn ident generics fn_decl_with_self where_clause inner_attrs_block
1299
- { ImplItem (unspan $7) (unspan $2) $3 ($1 ++ fst $>) (MethodI (MethodSig $5 Const Rust $9 $8{ whereClause = $10 }) (snd $>)) ($1 # $2 # snd $>) }
1294
+ { ImplItem (unspan $7) (unspan $2) (unspan $3) ($1 ++ fst $>) (MethodI (MethodSig (unspan $5) Const Rust $9 $8{ whereClause = $10 }) (snd $>)) ($1 # $2 # snd $>) }
1300
1295
| many(outer_attribute) vis def safety ext_abi fn ident generics fn_decl_with_self where_clause inner_attrs_block
1301
- { ImplItem (unspan $7) (unspan $2) $3 ($1 ++ fst $>) (MethodI (MethodSig $4 NotConst $5 $9 $8{ whereClause = $10 }) (snd $>)) ($1 # $2 # snd $>) }
1296
+ { ImplItem (unspan $7) (unspan $2) (unspan $3) ($1 ++ fst $>) (MethodI (MethodSig (unspan $4) NotConst (unspan $5) $9 $8{ whereClause = $10 }) (snd $>)) ($1 # $2 # snd $>) }
1302
1297
1303
1298
trait_item :: { TraitItem Span }
1304
1299
: ntTraitItem { $1 }
1305
1300
| many(outer_attribute) const ident ' :' ty initializer ' ;' { TraitItem (unspan $3) $1 (ConstT $5 $6) ($1 # $2 # $>) }
1306
1301
| many(outer_attribute) mod_mac { TraitItem (mkIdent "") $1 (MacroT $2) ($1 # $>) }
1307
1302
| many(outer_attribute) type ty_param ' ;' { let TyParam _ i b d _ = $3 in TraitItem i $1 (TypeT b d) ($1 # $2 # $>) }
1308
- | many(outer_attribute) safetyS ext_abiS fn ident generics fn_decl_with_self where_clause ' ;'
1303
+ | many(outer_attribute) safety ext_abi fn ident generics fn_decl_with_self where_clause ' ;'
1309
1304
{ TraitItem (unspan $5) $1 (MethodT (MethodSig (unspan $2) NotConst (unspan $3) $7 $6{ whereClause = $8 }) Nothing) ($1 # $2 # $3 # $4 # $>) }
1310
- | many(outer_attribute) safetyS ext_abiS fn ident generics fn_decl_with_self where_clause block
1305
+ | many(outer_attribute) safety ext_abi fn ident generics fn_decl_with_self where_clause block
1311
1306
{ TraitItem (unspan $5) $1 (MethodT (MethodSig (unspan $2) NotConst (unspan $3) $7 $6{ whereClause = $8 }) (Just $>)) ($1 # $2 # $3 # $4 # $>) }
1312
1307
1313
1308
1314
- safety :: { Unsafety }
1315
- : {- empty -} { Normal }
1316
- | unsafe { Unsafe }
1317
-
1318
- ext_abi :: { Abi }
1319
- : {- empty -} { Rust }
1320
- | extern abi { $2 }
1321
-
1322
- safetyS :: { Spanned Unsafety }
1309
+ safety :: { Spanned Unsafety }
1323
1310
: {- empty -} { pure Normal }
1324
1311
| unsafe { Spanned Unsafe (spanOf $1) }
1325
1312
1326
- ext_abiS :: { Spanned Abi }
1313
+ ext_abi :: { Spanned Abi }
1327
1314
: {- empty -} { pure Rust }
1328
1315
| extern abi { Spanned $2 (spanOf $1) }
1329
1316
@@ -1333,9 +1320,9 @@ vis :: { Spanned (Visibility Span) }
1333
1320
| pub ' (' crate ' )' { Spanned CrateV ($1 # $4) }
1334
1321
| pub ' (' mod_path ' )' { Spanned (RestrictedV $3) ($1 # $4) }
1335
1322
1336
- def :: { Defaultness }
1337
- : {- empty -} %prec mut { Final }
1338
- | default { Default }
1323
+ def :: { Spanned Defaultness }
1324
+ : {- empty -} %prec mut { pure Final }
1325
+ | default { Spanned Default (spanOf $1) }
1339
1326
1340
1327
view_path :: { ViewPath Span }
1341
1328
: ' ::' sep_by1(self_or_ident,' ::' ) { let n = fmap unspan $2 in ViewPathSimple True (N.init n) (PathListItem (N.last n) Nothing mempty) ($1 # $>) }
@@ -1435,7 +1422,7 @@ token :: { Spanned Token }
1435
1422
| ' <-' { $1 }
1436
1423
| ' =>' { $1 }
1437
1424
| ' #' { $1 }
1438
- | ' $' %prec DOLLAR { $1 }
1425
+ | ' $' { $1 }
1439
1426
| ' ?' { $1 }
1440
1427
| ' #!' { $1 }
1441
1428
-- Literals.
0 commit comments