@@ -121,24 +121,34 @@ impl<'a> PostExpansionVisitor<'a> {
121121 }
122122
123123 /// 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 ) {
125125 struct ImplTraitVisitor < ' a > {
126126 vis : & ' a PostExpansionVisitor < ' a > ,
127+ in_associated_ty : bool ,
127128 }
128129 impl Visitor < ' _ > for ImplTraitVisitor < ' _ > {
129130 fn visit_ty ( & mut self , ty : & ast:: Ty ) {
130131 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+ }
137147 }
138148 visit:: walk_ty ( self , ty) ;
139149 }
140150 }
141- ImplTraitVisitor { vis : self } . visit_ty ( ty) ;
151+ ImplTraitVisitor { vis : self , in_associated_ty } . visit_ty ( ty) ;
142152 }
143153
144154 fn check_late_bound_lifetime_defs ( & self , params : & [ ast:: GenericParam ] ) {
@@ -294,7 +304,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
294304 }
295305
296306 ast:: ItemKind :: TyAlias ( box ast:: TyAlias { ty : Some ( ty) , .. } ) => {
297- self . check_impl_trait ( & ty)
307+ self . check_impl_trait ( & ty, false )
298308 }
299309
300310 _ => { }
@@ -517,7 +527,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
517527 ) ;
518528 }
519529 if let Some ( ty) = ty {
520- self . check_impl_trait ( ty) ;
530+ self . check_impl_trait ( ty, true ) ;
521531 }
522532 false
523533 }
0 commit comments