@@ -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
_ => { }
@@ -517,7 +527,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
517
527
) ;
518
528
}
519
529
if let Some ( ty) = ty {
520
- self . check_impl_trait ( ty) ;
530
+ self . check_impl_trait ( ty, true ) ;
521
531
}
522
532
false
523
533
}
0 commit comments