@@ -3,12 +3,8 @@ use super::accepted::ACCEPTED_FEATURES;
3
3
use super :: removed:: { REMOVED_FEATURES , STABLE_REMOVED_FEATURES } ;
4
4
use super :: builtin_attrs:: { AttributeGate , BUILTIN_ATTRIBUTE_MAP } ;
5
5
6
- use crate :: ast:: {
7
- self , AssocTyConstraint , AssocTyConstraintKind , NodeId , GenericParam , GenericParamKind ,
8
- PatKind , RangeEnd , VariantData ,
9
- } ;
6
+ use crate :: ast:: { self , NodeId , PatKind , VariantData } ;
10
7
use crate :: attr:: { self , check_builtin_attribute} ;
11
- use crate :: source_map:: Spanned ;
12
8
use crate :: edition:: { ALL_EDITIONS , Edition } ;
13
9
use crate :: visit:: { self , FnKind , Visitor } ;
14
10
use crate :: parse:: token;
@@ -157,9 +153,6 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
157
153
158
154
}
159
155
160
- const EXPLAIN_BOX_SYNTAX : & str =
161
- "box expression syntax is experimental; you can call `Box::new` instead" ;
162
-
163
156
pub const EXPLAIN_STMT_ATTR_SYNTAX : & str =
164
157
"attributes on expressions are experimental" ;
165
158
@@ -291,6 +284,25 @@ impl<'a> PostExpansionVisitor<'a> {
291
284
err. emit ( ) ;
292
285
}
293
286
}
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
+ }
294
306
}
295
307
296
308
impl < ' a > Visitor < ' a > for PostExpansionVisitor < ' a > {
@@ -423,20 +435,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
423
435
"auto traits are experimental and possibly buggy" ) ;
424
436
}
425
437
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
-
440
438
ast:: ItemKind :: OpaqueTy ( ..) => {
441
439
gate_feature_post ! (
442
440
& self ,
@@ -500,37 +498,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
500
498
}
501
499
}
502
500
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
-
534
501
fn visit_pat ( & mut self , pattern : & ' a ast:: Pat ) {
535
502
match & pattern. kind {
536
503
PatKind :: Slice ( pats) => {
@@ -550,25 +517,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
550
517
}
551
518
}
552
519
}
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
- }
562
520
_ => { }
563
521
}
564
522
visit:: walk_pat ( self , pattern)
565
523
}
566
524
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 ) {
572
526
if let Some ( header) = fn_kind. header ( ) {
573
527
// Stability of const fn methods are covered in
574
528
// `visit_trait_item` and `visit_impl_item` below; this is
@@ -583,26 +537,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
583
537
visit:: walk_fn ( self , fn_kind, fn_decl, span)
584
538
}
585
539
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
-
606
540
fn visit_trait_item ( & mut self , ti : & ' a ast:: TraitItem ) {
607
541
match ti. kind {
608
542
ast:: TraitItemKind :: Method ( ref sig, ref block) => {
@@ -624,14 +558,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
624
558
gate_feature_post ! ( & self , associated_type_defaults, ti. span,
625
559
"associated type defaults are unstable" ) ;
626
560
}
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 ) ;
635
562
}
636
563
_ => { }
637
564
}
@@ -661,27 +588,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
661
588
) ;
662
589
}
663
590
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 ) ;
672
592
}
673
593
_ => { }
674
594
}
675
595
visit:: walk_impl_item ( self , ii)
676
596
}
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
- }
685
597
}
686
598
687
599
pub fn get_features ( span_handler : & Handler , krate_attrs : & [ ast:: Attribute ] ,
@@ -867,6 +779,22 @@ pub fn check_crate(krate: &ast::Crate,
867
779
gate_all ! ( yields, generators, "yield syntax is experimental" ) ;
868
780
gate_all ! ( or_patterns, "or-patterns syntax is experimental" ) ;
869
781
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
+ }
870
798
871
799
visit:: walk_crate ( & mut visitor, krate) ;
872
800
}
0 commit comments