@@ -3,12 +3,8 @@ use super::accepted::ACCEPTED_FEATURES;
33use super :: removed:: { REMOVED_FEATURES , STABLE_REMOVED_FEATURES } ;
44use super :: builtin_attrs:: { AttributeGate , BUILTIN_ATTRIBUTE_MAP } ;
55
6- use crate :: ast:: {
7- self , AssocTyConstraint , AssocTyConstraintKind , NodeId , GenericParam , GenericParamKind ,
8- PatKind , RangeEnd , VariantData ,
9- } ;
6+ use crate :: ast:: { self , NodeId , PatKind , VariantData } ;
107use crate :: attr:: { self , check_builtin_attribute} ;
11- use crate :: source_map:: Spanned ;
128use crate :: edition:: { ALL_EDITIONS , Edition } ;
139use crate :: visit:: { self , FnKind , Visitor } ;
1410use crate :: parse:: token;
@@ -157,9 +153,6 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
157153
158154}
159155
160- const EXPLAIN_BOX_SYNTAX : & str =
161- "box expression syntax is experimental; you can call `Box::new` instead" ;
162-
163156pub const EXPLAIN_STMT_ATTR_SYNTAX : & str =
164157 "attributes on expressions are experimental" ;
165158
@@ -291,6 +284,25 @@ impl<'a> PostExpansionVisitor<'a> {
291284 err. emit ( ) ;
292285 }
293286 }
287+
288+ fn check_gat ( & self , generics : & ast:: Generics , span : Span ) {
289+ if !generics. params . is_empty ( ) {
290+ gate_feature_post ! (
291+ & self ,
292+ generic_associated_types,
293+ span,
294+ "generic associated types are unstable"
295+ ) ;
296+ }
297+ if !generics. where_clause . predicates . is_empty ( ) {
298+ gate_feature_post ! (
299+ & self ,
300+ generic_associated_types,
301+ span,
302+ "where clauses on associated types are unstable"
303+ ) ;
304+ }
305+ }
294306}
295307
296308impl < ' a > Visitor < ' a > for PostExpansionVisitor < ' a > {
@@ -423,20 +435,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
423435 "auto traits are experimental and possibly buggy" ) ;
424436 }
425437
426- ast:: ItemKind :: TraitAlias ( ..) => {
427- gate_feature_post ! (
428- & self ,
429- trait_alias,
430- i. span,
431- "trait aliases are experimental"
432- ) ;
433- }
434-
435- ast:: ItemKind :: MacroDef ( ast:: MacroDef { legacy : false , .. } ) => {
436- let msg = "`macro` is experimental" ;
437- gate_feature_post ! ( & self , decl_macro, i. span, msg) ;
438- }
439-
440438 ast:: ItemKind :: OpaqueTy ( ..) => {
441439 gate_feature_post ! (
442440 & self ,
@@ -500,37 +498,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
500498 }
501499 }
502500
503- fn visit_expr ( & mut self , e : & ' a ast:: Expr ) {
504- match e. kind {
505- ast:: ExprKind :: Box ( _) => {
506- gate_feature_post ! ( & self , box_syntax, e. span, EXPLAIN_BOX_SYNTAX ) ;
507- }
508- ast:: ExprKind :: Type ( ..) => {
509- // To avoid noise about type ascription in common syntax errors, only emit if it
510- // is the *only* error.
511- if self . parse_sess . span_diagnostic . err_count ( ) == 0 {
512- gate_feature_post ! ( & self , type_ascription, e. span,
513- "type ascription is experimental" ) ;
514- }
515- }
516- ast:: ExprKind :: TryBlock ( _) => {
517- gate_feature_post ! ( & self , try_blocks, e. span, "`try` expression is experimental" ) ;
518- }
519- ast:: ExprKind :: Block ( _, opt_label) => {
520- if let Some ( label) = opt_label {
521- gate_feature_post ! ( & self , label_break_value, label. ident. span,
522- "labels on blocks are unstable" ) ;
523- }
524- }
525- _ => { }
526- }
527- visit:: walk_expr ( self , e)
528- }
529-
530- fn visit_arm ( & mut self , arm : & ' a ast:: Arm ) {
531- visit:: walk_arm ( self , arm)
532- }
533-
534501 fn visit_pat ( & mut self , pattern : & ' a ast:: Pat ) {
535502 match & pattern. kind {
536503 PatKind :: Slice ( pats) => {
@@ -550,25 +517,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
550517 }
551518 }
552519 }
553- PatKind :: Box ( ..) => {
554- gate_feature_post ! ( & self , box_patterns,
555- pattern. span,
556- "box pattern syntax is experimental" ) ;
557- }
558- PatKind :: Range ( _, _, Spanned { node : RangeEnd :: Excluded , .. } ) => {
559- gate_feature_post ! ( & self , exclusive_range_pattern, pattern. span,
560- "exclusive range pattern syntax is experimental" ) ;
561- }
562520 _ => { }
563521 }
564522 visit:: walk_pat ( self , pattern)
565523 }
566524
567- fn visit_fn ( & mut self ,
568- fn_kind : FnKind < ' a > ,
569- fn_decl : & ' a ast:: FnDecl ,
570- span : Span ,
571- _node_id : NodeId ) {
525+ fn visit_fn ( & mut self , fn_kind : FnKind < ' a > , fn_decl : & ' a ast:: FnDecl , span : Span , _: NodeId ) {
572526 if let Some ( header) = fn_kind. header ( ) {
573527 // Stability of const fn methods are covered in
574528 // `visit_trait_item` and `visit_impl_item` below; this is
@@ -583,26 +537,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
583537 visit:: walk_fn ( self , fn_kind, fn_decl, span)
584538 }
585539
586- fn visit_generic_param ( & mut self , param : & ' a GenericParam ) {
587- match param. kind {
588- GenericParamKind :: Const { .. } =>
589- gate_feature_post ! ( & self , const_generics, param. ident. span,
590- "const generics are unstable" ) ,
591- _ => { }
592- }
593- visit:: walk_generic_param ( self , param)
594- }
595-
596- fn visit_assoc_ty_constraint ( & mut self , constraint : & ' a AssocTyConstraint ) {
597- match constraint. kind {
598- AssocTyConstraintKind :: Bound { .. } =>
599- gate_feature_post ! ( & self , associated_type_bounds, constraint. span,
600- "associated type bounds are unstable" ) ,
601- _ => { }
602- }
603- visit:: walk_assoc_ty_constraint ( self , constraint)
604- }
605-
606540 fn visit_trait_item ( & mut self , ti : & ' a ast:: TraitItem ) {
607541 match ti. kind {
608542 ast:: TraitItemKind :: Method ( ref sig, ref block) => {
@@ -624,14 +558,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
624558 gate_feature_post ! ( & self , associated_type_defaults, ti. span,
625559 "associated type defaults are unstable" ) ;
626560 }
627- if !ti. generics . params . is_empty ( ) {
628- gate_feature_post ! ( & self , generic_associated_types, ti. span,
629- "generic associated types are unstable" ) ;
630- }
631- if !ti. generics . where_clause . predicates . is_empty ( ) {
632- gate_feature_post ! ( & self , generic_associated_types, ti. span,
633- "where clauses on associated types are unstable" ) ;
634- }
561+ self . check_gat ( & ti. generics , ti. span ) ;
635562 }
636563 _ => { }
637564 }
@@ -661,27 +588,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
661588 ) ;
662589 }
663590 ast:: ImplItemKind :: TyAlias ( _) => {
664- if !ii. generics . params . is_empty ( ) {
665- gate_feature_post ! ( & self , generic_associated_types, ii. span,
666- "generic associated types are unstable" ) ;
667- }
668- if !ii. generics . where_clause . predicates . is_empty ( ) {
669- gate_feature_post ! ( & self , generic_associated_types, ii. span,
670- "where clauses on associated types are unstable" ) ;
671- }
591+ self . check_gat ( & ii. generics , ii. span ) ;
672592 }
673593 _ => { }
674594 }
675595 visit:: walk_impl_item ( self , ii)
676596 }
677-
678- fn visit_vis ( & mut self , vis : & ' a ast:: Visibility ) {
679- if let ast:: VisibilityKind :: Crate ( ast:: CrateSugar :: JustCrate ) = vis. node {
680- gate_feature_post ! ( & self , crate_visibility_modifier, vis. span,
681- "`crate` visibility modifier is experimental" ) ;
682- }
683- visit:: walk_vis ( self , vis)
684- }
685597}
686598
687599pub fn get_features ( span_handler : & Handler , krate_attrs : & [ ast:: Attribute ] ,
@@ -867,6 +779,22 @@ pub fn check_crate(krate: &ast::Crate,
867779 gate_all ! ( yields, generators, "yield syntax is experimental" ) ;
868780 gate_all ! ( or_patterns, "or-patterns syntax is experimental" ) ;
869781 gate_all ! ( const_extern_fn, "`const extern fn` definitions are unstable" ) ;
782+ gate_all ! ( trait_alias, "trait aliases are experimental" ) ;
783+ gate_all ! ( associated_type_bounds, "associated type bounds are unstable" ) ;
784+ gate_all ! ( crate_visibility_modifier, "`crate` visibility modifier is experimental" ) ;
785+ gate_all ! ( const_generics, "const generics are unstable" ) ;
786+ gate_all ! ( decl_macro, "`macro` is experimental" ) ;
787+ gate_all ! ( box_patterns, "box pattern syntax is experimental" ) ;
788+ gate_all ! ( exclusive_range_pattern, "exclusive range pattern syntax is experimental" ) ;
789+ gate_all ! ( try_blocks, "`try` blocks are unstable" ) ;
790+ gate_all ! ( label_break_value, "labels on blocks are unstable" ) ;
791+ gate_all ! ( box_syntax, "box expression syntax is experimental; you can call `Box::new` instead" ) ;
792+
793+ // To avoid noise about type ascription in common syntax errors,
794+ // only emit if it is the *only* error. (Also check it last.)
795+ if parse_sess. span_diagnostic . err_count ( ) == 0 {
796+ gate_all ! ( type_ascription, "type ascription is experimental" ) ;
797+ }
870798
871799 visit:: walk_crate ( & mut visitor, krate) ;
872800}
0 commit comments