@@ -121,24 +121,34 @@ impl<'a> PostExpansionVisitor<'a> {
121
121
}
122
122
123
123
/// Feature gate `impl Trait` inside `type Alias = $type_expr;`.
124
- fn check_impl_trait ( & self , ty : & ast:: Ty ) {
124
+ fn check_impl_trait ( & self , ty : & ast:: Ty , in_associated_ty : bool ) {
125
125
struct ImplTraitVisitor < ' a > {
126
126
vis : & ' a PostExpansionVisitor < ' a > ,
127
+ in_associated_ty : bool ,
127
128
}
128
129
impl Visitor < ' _ > for ImplTraitVisitor < ' _ > {
129
130
fn visit_ty ( & mut self , ty : & ast:: Ty ) {
130
131
if let ast:: TyKind :: ImplTrait ( ..) = ty. kind {
131
- gate_feature_post ! (
132
- & self . vis,
133
- type_alias_impl_trait,
134
- ty. span,
135
- "`impl Trait` in type aliases is unstable"
136
- ) ;
132
+ if self . in_associated_ty {
133
+ gate_feature_post ! (
134
+ & self . vis,
135
+ impl_trait_in_assoc_type,
136
+ ty. span,
137
+ "`impl Trait` in associated types is unstable"
138
+ ) ;
139
+ } else {
140
+ gate_feature_post ! (
141
+ & self . vis,
142
+ type_alias_impl_trait,
143
+ ty. span,
144
+ "`impl Trait` in type aliases is unstable"
145
+ ) ;
146
+ }
137
147
}
138
148
visit:: walk_ty ( self , ty) ;
139
149
}
140
150
}
141
- ImplTraitVisitor { vis : self } . visit_ty ( ty) ;
151
+ ImplTraitVisitor { vis : self , in_associated_ty } . visit_ty ( ty) ;
142
152
}
143
153
144
154
fn check_late_bound_lifetime_defs ( & self , params : & [ ast:: GenericParam ] ) {
@@ -294,7 +304,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
294
304
}
295
305
296
306
ast:: ItemKind :: TyAlias ( box ast:: TyAlias { ty : Some ( ty) , .. } ) => {
297
- self . check_impl_trait ( & ty)
307
+ self . check_impl_trait ( & ty, false )
298
308
}
299
309
300
310
_ => { }
@@ -485,20 +495,23 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
485
495
486
496
fn visit_assoc_constraint ( & mut self , constraint : & ' a AssocConstraint ) {
487
497
if let AssocConstraintKind :: Bound { .. } = constraint. kind {
488
- if let Some ( args) = constraint. gen_args . as_ref ( )
489
- && matches ! (
490
- args,
491
- ast:: GenericArgs :: ReturnTypeNotation ( ..)
492
- )
498
+ if let Some ( ast:: GenericArgs :: Parenthesized ( args) ) = constraint. gen_args . as_ref ( )
499
+ && args. inputs . is_empty ( )
500
+ && matches ! ( args. output, ast:: FnRetTy :: Default ( ..) )
493
501
{
494
- // RTN is gated below with a `gate_all`.
502
+ gate_feature_post ! (
503
+ & self ,
504
+ return_type_notation,
505
+ constraint. span,
506
+ "return type notation is experimental"
507
+ ) ;
495
508
} else {
496
509
gate_feature_post ! (
497
510
& self ,
498
511
associated_type_bounds,
499
512
constraint. span,
500
513
"associated type bounds are unstable"
501
- )
514
+ ) ;
502
515
}
503
516
}
504
517
visit:: walk_assoc_constraint ( self , constraint)
@@ -517,7 +530,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
517
530
) ;
518
531
}
519
532
if let Some ( ty) = ty {
520
- self . check_impl_trait ( ty) ;
533
+ self . check_impl_trait ( ty, true ) ;
521
534
}
522
535
false
523
536
}
@@ -589,7 +602,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
589
602
gate_all ! ( yeet_expr, "`do yeet` expression is experimental" ) ;
590
603
gate_all ! ( dyn_star, "`dyn*` trait objects are experimental" ) ;
591
604
gate_all ! ( const_closures, "const closures are experimental" ) ;
592
- gate_all ! ( return_type_notation, "return type notation is experimental" ) ;
593
605
594
606
// All uses of `gate_all!` below this point were added in #65742,
595
607
// and subsequently disabled (with the non-early gating readded).
@@ -605,6 +617,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
605
617
606
618
gate_all ! ( trait_alias, "trait aliases are experimental" ) ;
607
619
gate_all ! ( associated_type_bounds, "associated type bounds are unstable" ) ;
620
+ gate_all ! ( return_type_notation, "return type notation is experimental" ) ;
608
621
gate_all ! ( decl_macro, "`macro` is experimental" ) ;
609
622
gate_all ! ( box_patterns, "box pattern syntax is experimental" ) ;
610
623
gate_all ! ( exclusive_range_pattern, "exclusive range pattern syntax is experimental" ) ;
0 commit comments