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