@@ -317,6 +317,27 @@ impl<'a> PostExpansionVisitor<'a> {
317317 ) ;
318318 }
319319 }
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+ }
320341}
321342
322343impl < ' a > Visitor < ' a > for PostExpansionVisitor < ' a > {
@@ -451,14 +472,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
451472 gate_feature_post ! ( & self , decl_macro, i. span, msg) ;
452473 }
453474
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) ,
462476
463477 _ => { }
464478 }
@@ -632,9 +646,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
632646 }
633647 }
634648 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) ;
638651 gate_feature_post ! ( & self , associated_type_defaults, ti. span,
639652 "associated type defaults are unstable" ) ;
640653 }
@@ -659,15 +672,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
659672 "C-variadic functions are unstable" ) ;
660673 }
661674 }
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) ;
671677 self . check_gat ( & ii. generics , ii. span ) ;
672678 }
673679 _ => { }
0 commit comments