@@ -318,6 +318,27 @@ impl<'a> PostExpansionVisitor<'a> {
318
318
) ;
319
319
}
320
320
}
321
+
322
+ /// Feature gate `impl Trait` inside `type Alias = $type_expr;`.
323
+ fn check_impl_trait ( & self , ty : & ast:: Ty ) {
324
+ struct ImplTraitVisitor < ' a > {
325
+ vis : & ' a PostExpansionVisitor < ' a > ,
326
+ }
327
+ impl Visitor < ' _ > for ImplTraitVisitor < ' _ > {
328
+ fn visit_ty ( & mut self , ty : & ast:: Ty ) {
329
+ if let ast:: TyKind :: ImplTrait ( ..) = ty. kind {
330
+ gate_feature_post ! (
331
+ & self . vis,
332
+ type_alias_impl_trait,
333
+ ty. span,
334
+ "`impl Trait` in type aliases is unstable"
335
+ ) ;
336
+ }
337
+ visit:: walk_ty ( self , ty) ;
338
+ }
339
+ }
340
+ ImplTraitVisitor { vis : self } . visit_ty ( ty) ;
341
+ }
321
342
}
322
343
323
344
impl < ' a > Visitor < ' a > for PostExpansionVisitor < ' a > {
@@ -452,14 +473,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
452
473
gate_feature_post ! ( & self , decl_macro, i. span, msg) ;
453
474
}
454
475
455
- ast:: ItemKind :: OpaqueTy ( ..) => {
456
- gate_feature_post ! (
457
- & self ,
458
- type_alias_impl_trait,
459
- i. span,
460
- "`impl Trait` in type aliases is unstable"
461
- ) ;
462
- }
476
+ ast:: ItemKind :: TyAlias ( ref ty, ..) => self . check_impl_trait ( & ty) ,
463
477
464
478
_ => { }
465
479
}
@@ -633,9 +647,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
633
647
}
634
648
}
635
649
ast:: TraitItemKind :: Type ( _, ref default) => {
636
- // We use three if statements instead of something like match guards so that all
637
- // of these errors can be emitted if all cases apply.
638
- if default. is_some ( ) {
650
+ if let Some ( ty) = default {
651
+ self . check_impl_trait ( ty) ;
639
652
gate_feature_post ! ( & self , associated_type_defaults, ti. span,
640
653
"associated type defaults are unstable" ) ;
641
654
}
@@ -660,15 +673,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
660
673
"C-variadic functions are unstable" ) ;
661
674
}
662
675
}
663
- ast:: ImplItemKind :: OpaqueTy ( ..) => {
664
- gate_feature_post ! (
665
- & self ,
666
- type_alias_impl_trait,
667
- ii. span,
668
- "`impl Trait` in type aliases is unstable"
669
- ) ;
670
- }
671
- ast:: ImplItemKind :: TyAlias ( _) => {
676
+ ast:: ImplItemKind :: TyAlias ( ref ty) => {
677
+ self . check_impl_trait ( ty) ;
672
678
self . check_gat ( & ii. generics , ii. span ) ;
673
679
}
674
680
_ => { }
0 commit comments