@@ -152,6 +152,12 @@ extern char *yytext;
152152%precedence MOD_SEP
153153%precedence RARROW ':'
154154
155+ // In where clauses, "for" should have greater precedence when used as
156+ // a higher ranked constraint than when used as the beginning of a
157+ // for_in_type (which is a ty)
158+ %precedence FORTYPE
159+ %precedence FOR
160+
155161// Binops & unops, and their precedences
156162%precedence BOX
157163%precedence BOXPLACE
@@ -582,6 +588,14 @@ item_impl
582588{
583589 $$ = mk_node("ItemImplNeg", 7, $1, $3, $5, $7, $8, $10, $11);
584590}
591+ | maybe_unsafe IMPL generic_params trait_ref FOR DOTDOT '{' '}'
592+ {
593+ $$ = mk_node("ItemImplDefault", 3, $1, $3, $4);
594+ }
595+ | maybe_unsafe IMPL generic_params '!' trait_ref FOR DOTDOT '{' '}'
596+ {
597+ $$ = mk_node("ItemImplDefaultNeg", 3, $1, $3, $4);
598+ }
585599;
586600
587601maybe_impl_items
@@ -769,10 +783,14 @@ where_predicates
769783;
770784
771785where_predicate
772- : lifetime ':' bounds { $$ = mk_node("WherePredicate", 2 , $1, $3 ); }
773- | ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 2 , $1, $3 ); }
786+ : maybe_for_lifetimes lifetime ':' bounds { $$ = mk_node("WherePredicate", 3 , $1, $2, $4 ); }
787+ | maybe_for_lifetimes ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 3 , $1, $2, $4 ); }
774788;
775789
790+ maybe_for_lifetimes
791+ : FOR '<' lifetimes '>' { $$ = mk_none(); }
792+ | %prec FORTYPE %empty { $$ = mk_none(); }
793+
776794ty_params
777795: ty_param { $$ = mk_node("TyParams", 1, $1); }
778796| ty_params ',' ty_param { $$ = ext_node($1, 1, $3); }
@@ -1024,7 +1042,8 @@ ty_qualified_path_and_generic_values
10241042}
10251043| ty_qualified_path ',' ty_sums maybe_bindings
10261044{
1027- $$ = mk_node("GenericValues", 3, mk_none(), ext_node(mk_node("TySums", 1, $1), 1, $3), $4); }
1045+ $$ = mk_node("GenericValues", 3, mk_none(), mk_node("TySums", 2, $1, $3), $4);
1046+ }
10281047;
10291048
10301049ty_qualified_path
@@ -1513,31 +1532,35 @@ nonblock_prefix_expr
15131532;
15141533
15151534expr_qualified_path
1516- : '<' ty_sum AS trait_ref '>' MOD_SEP ident
1535+ : '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident
15171536{
1518- $$ = mk_node("ExprQualifiedPath", 3, $2, $4 , $7 );
1537+ $$ = mk_node("ExprQualifiedPath", 3, $2, $3 , $6 );
15191538}
1520- | '<' ty_sum AS trait_ref '>' MOD_SEP ident generic_args
1539+ | '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args
15211540{
1522- $$ = mk_node("ExprQualifiedPath", 4, $2, $4 , $7 , $8 );
1541+ $$ = mk_node("ExprQualifiedPath", 4, $2, $3 , $6 , $7 );
15231542}
1524- | SHL ty_sum AS trait_ref '>' MOD_SEP ident AS trait_ref '>' MOD_SEP ident
1543+ | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident
15251544{
1526- $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 3, $2, $4 , $7 ), $9 , $12 );
1545+ $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 3, $2, $3 , $6 ), $7 , $10 );
15271546}
1528- | SHL ty_sum AS trait_ref '>' MOD_SEP ident generic_args AS trait_ref '>' MOD_SEP ident
1547+ | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args maybe_as_trait_ref '>' MOD_SEP ident
15291548{
1530- $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 4, $2, $4 , $7 , $8 ), $10 , $13 );
1549+ $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 4, $2, $3 , $6 , $7 ), $8 , $11 );
15311550}
1532- | SHL ty_sum AS trait_ref '>' MOD_SEP ident AS trait_ref '>' MOD_SEP ident generic_args
1551+ | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident generic_args
15331552{
1534- $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 3, $2, $4 , $7 ), $9 , $12 , $13 );
1553+ $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 3, $2, $3 , $6 ), $7 , $10 , $11 );
15351554}
1536- | SHL ty_sum AS trait_ref '>' MOD_SEP ident generic_args AS trait_ref '>' MOD_SEP ident generic_args
1555+ | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args maybe_as_trait_ref '>' MOD_SEP ident generic_args
15371556{
1538- $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 4, $2, $4 , $7 , $8 ), $10 , $13 , $14 );
1557+ $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 4, $2, $3 , $6 , $7 ), $8 , $11 , $12 );
15391558}
15401559
1560+ maybe_as_trait_ref
1561+ : AS trait_ref { $$ = $2; }
1562+ | %empty { $$ = mk_none(); }
1563+ ;
15411564
15421565lambda_expr
15431566: %prec LAMBDA
0 commit comments