@@ -3,8 +3,12 @@ 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:: { self , NodeId , PatKind , VariantData } ;
6
+ use crate :: ast:: {
7
+ self , AssocTyConstraint , AssocTyConstraintKind , NodeId , GenericParam , GenericParamKind ,
8
+ PatKind , RangeEnd , VariantData ,
9
+ } ;
7
10
use crate :: attr:: { self , check_builtin_attribute} ;
11
+ use crate :: source_map:: Spanned ;
8
12
use crate :: edition:: { ALL_EDITIONS , Edition } ;
9
13
use crate :: visit:: { self , FnKind , Visitor } ;
10
14
use crate :: parse:: token;
@@ -153,6 +157,9 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
153
157
154
158
}
155
159
160
+ const EXPLAIN_BOX_SYNTAX : & str =
161
+ "box expression syntax is experimental; you can call `Box::new` instead" ;
162
+
156
163
pub const EXPLAIN_STMT_ATTR_SYNTAX : & str =
157
164
"attributes on expressions are experimental" ;
158
165
@@ -439,6 +446,20 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
439
446
"auto traits are experimental and possibly buggy" ) ;
440
447
}
441
448
449
+ ast:: ItemKind :: TraitAlias ( ..) => {
450
+ gate_feature_post ! (
451
+ & self ,
452
+ trait_alias,
453
+ i. span,
454
+ "trait aliases are experimental"
455
+ ) ;
456
+ }
457
+
458
+ ast:: ItemKind :: MacroDef ( ast:: MacroDef { legacy : false , .. } ) => {
459
+ let msg = "`macro` is experimental" ;
460
+ gate_feature_post ! ( & self , decl_macro, i. span, msg) ;
461
+ }
462
+
442
463
ast:: ItemKind :: OpaqueTy ( ..) => {
443
464
gate_feature_post ! (
444
465
& self ,
@@ -502,6 +523,37 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
502
523
}
503
524
}
504
525
526
+ fn visit_expr ( & mut self , e : & ' a ast:: Expr ) {
527
+ match e. kind {
528
+ ast:: ExprKind :: Box ( _) => {
529
+ gate_feature_post ! ( & self , box_syntax, e. span, EXPLAIN_BOX_SYNTAX ) ;
530
+ }
531
+ ast:: ExprKind :: Type ( ..) => {
532
+ // To avoid noise about type ascription in common syntax errors, only emit if it
533
+ // is the *only* error.
534
+ if self . parse_sess . span_diagnostic . err_count ( ) == 0 {
535
+ gate_feature_post ! ( & self , type_ascription, e. span,
536
+ "type ascription is experimental" ) ;
537
+ }
538
+ }
539
+ ast:: ExprKind :: TryBlock ( _) => {
540
+ gate_feature_post ! ( & self , try_blocks, e. span, "`try` expression is experimental" ) ;
541
+ }
542
+ ast:: ExprKind :: Block ( _, opt_label) => {
543
+ if let Some ( label) = opt_label {
544
+ gate_feature_post ! ( & self , label_break_value, label. ident. span,
545
+ "labels on blocks are unstable" ) ;
546
+ }
547
+ }
548
+ _ => { }
549
+ }
550
+ visit:: walk_expr ( self , e)
551
+ }
552
+
553
+ fn visit_arm ( & mut self , arm : & ' a ast:: Arm ) {
554
+ visit:: walk_arm ( self , arm)
555
+ }
556
+
505
557
fn visit_pat ( & mut self , pattern : & ' a ast:: Pat ) {
506
558
match & pattern. kind {
507
559
PatKind :: Slice ( pats) => {
@@ -521,12 +573,25 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
521
573
}
522
574
}
523
575
}
576
+ PatKind :: Box ( ..) => {
577
+ gate_feature_post ! ( & self , box_patterns,
578
+ pattern. span,
579
+ "box pattern syntax is experimental" ) ;
580
+ }
581
+ PatKind :: Range ( _, _, Spanned { node : RangeEnd :: Excluded , .. } ) => {
582
+ gate_feature_post ! ( & self , exclusive_range_pattern, pattern. span,
583
+ "exclusive range pattern syntax is experimental" ) ;
584
+ }
524
585
_ => { }
525
586
}
526
587
visit:: walk_pat ( self , pattern)
527
588
}
528
589
529
- fn visit_fn ( & mut self , fn_kind : FnKind < ' a > , fn_decl : & ' a ast:: FnDecl , span : Span , _: NodeId ) {
590
+ fn visit_fn ( & mut self ,
591
+ fn_kind : FnKind < ' a > ,
592
+ fn_decl : & ' a ast:: FnDecl ,
593
+ span : Span ,
594
+ _node_id : NodeId ) {
530
595
if let Some ( header) = fn_kind. header ( ) {
531
596
// Stability of const fn methods are covered in
532
597
// `visit_trait_item` and `visit_impl_item` below; this is
@@ -541,6 +606,26 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
541
606
visit:: walk_fn ( self , fn_kind, fn_decl, span)
542
607
}
543
608
609
+ fn visit_generic_param ( & mut self , param : & ' a GenericParam ) {
610
+ match param. kind {
611
+ GenericParamKind :: Const { .. } =>
612
+ gate_feature_post ! ( & self , const_generics, param. ident. span,
613
+ "const generics are unstable" ) ,
614
+ _ => { }
615
+ }
616
+ visit:: walk_generic_param ( self , param)
617
+ }
618
+
619
+ fn visit_assoc_ty_constraint ( & mut self , constraint : & ' a AssocTyConstraint ) {
620
+ match constraint. kind {
621
+ AssocTyConstraintKind :: Bound { .. } =>
622
+ gate_feature_post ! ( & self , associated_type_bounds, constraint. span,
623
+ "associated type bounds are unstable" ) ,
624
+ _ => { }
625
+ }
626
+ visit:: walk_assoc_ty_constraint ( self , constraint)
627
+ }
628
+
544
629
fn visit_trait_item ( & mut self , ti : & ' a ast:: TraitItem ) {
545
630
match ti. kind {
546
631
ast:: TraitItemKind :: Method ( ref sig, ref block) => {
@@ -598,6 +683,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
598
683
}
599
684
visit:: walk_impl_item ( self , ii)
600
685
}
686
+
687
+ fn visit_vis ( & mut self , vis : & ' a ast:: Visibility ) {
688
+ if let ast:: VisibilityKind :: Crate ( ast:: CrateSugar :: JustCrate ) = vis. node {
689
+ gate_feature_post ! ( & self , crate_visibility_modifier, vis. span,
690
+ "`crate` visibility modifier is experimental" ) ;
691
+ }
692
+ visit:: walk_vis ( self , vis)
693
+ }
601
694
}
602
695
603
696
pub fn get_features ( span_handler : & Handler , krate_attrs : & [ ast:: Attribute ] ,
@@ -783,6 +876,21 @@ pub fn check_crate(krate: &ast::Crate,
783
876
gate_all ! ( yields, generators, "yield syntax is experimental" ) ;
784
877
gate_all ! ( or_patterns, "or-patterns syntax is experimental" ) ;
785
878
gate_all ! ( const_extern_fn, "`const extern fn` definitions are unstable" ) ;
879
+
880
+ // All uses of `gate_all!` below this point were added in #65742,
881
+ // and subsequently disabled (with the non-early gating readded).
882
+ macro_rules! gate_all {
883
+ ( $gate: ident, $msg: literal) => {
884
+ // FIXME(eddyb) do something more useful than always
885
+ // disabling these uses of early feature-gatings.
886
+ if false {
887
+ for span in & * parse_sess. gated_spans. $gate. borrow( ) {
888
+ gate_feature!( & visitor, $gate, * span, $msg) ;
889
+ }
890
+ }
891
+ }
892
+ }
893
+
786
894
gate_all ! ( trait_alias, "trait aliases are experimental" ) ;
787
895
gate_all ! ( associated_type_bounds, "associated type bounds are unstable" ) ;
788
896
gate_all ! ( crate_visibility_modifier, "`crate` visibility modifier is experimental" ) ;
0 commit comments