@@ -318,6 +318,27 @@ impl<'a> PostExpansionVisitor<'a> {
318318 ) ;
319319 }
320320 }
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+ }
321342}
322343
323344impl < ' a > Visitor < ' a > for PostExpansionVisitor < ' a > {
@@ -452,14 +473,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
452473 gate_feature_post ! ( & self , decl_macro, i. span, msg) ;
453474 }
454475
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) ,
463477
464478 _ => { }
465479 }
@@ -633,9 +647,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
633647 }
634648 }
635649 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) ;
639652 gate_feature_post ! ( & self , associated_type_defaults, ti. span,
640653 "associated type defaults are unstable" ) ;
641654 }
@@ -660,15 +673,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
660673 "C-variadic functions are unstable" ) ;
661674 }
662675 }
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) ;
672678 self . check_gat ( & ii. generics , ii. span ) ;
673679 }
674680 _ => { }
0 commit comments