@@ -2,10 +2,10 @@ use rustc_ast as ast;
2
2
use rustc_ast:: visit:: { self , AssocCtxt , FnCtxt , FnKind , Visitor } ;
3
3
use rustc_ast:: { AssocConstraint , AssocConstraintKind , NodeId } ;
4
4
use rustc_ast:: { PatKind , RangeEnd , VariantData } ;
5
- use rustc_errors:: { struct_span_err, Applicability } ;
5
+ use rustc_errors:: { struct_span_err, Applicability , StashKey } ;
6
+ use rustc_feature:: Features ;
6
7
use rustc_feature:: { AttributeGate , BuiltinAttribute , BUILTIN_ATTRIBUTE_MAP } ;
7
- use rustc_feature:: { Features , GateIssue } ;
8
- use rustc_session:: parse:: { feature_err, feature_err_issue} ;
8
+ use rustc_session:: parse:: { feature_err, feature_warn} ;
9
9
use rustc_session:: Session ;
10
10
use rustc_span:: source_map:: Spanned ;
11
11
use rustc_span:: symbol:: sym;
@@ -20,9 +20,7 @@ macro_rules! gate_feature_fn {
20
20
let has_feature: bool = has_feature( visitor. features) ;
21
21
debug!( "gate_feature(feature = {:?}, span = {:?}); has? {}" , name, span, has_feature) ;
22
22
if !has_feature && !span. allows_unstable( $name) {
23
- feature_err_issue( & visitor. sess. parse_sess, name, span, GateIssue :: Language , explain)
24
- . help( help)
25
- . emit( ) ;
23
+ feature_err( & visitor. sess. parse_sess, name, span, explain) . help( help) . emit( ) ;
26
24
}
27
25
} } ;
28
26
( $visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => { {
@@ -31,8 +29,19 @@ macro_rules! gate_feature_fn {
31
29
let has_feature: bool = has_feature( visitor. features) ;
32
30
debug!( "gate_feature(feature = {:?}, span = {:?}); has? {}" , name, span, has_feature) ;
33
31
if !has_feature && !span. allows_unstable( $name) {
34
- feature_err_issue( & visitor. sess. parse_sess, name, span, GateIssue :: Language , explain)
35
- . emit( ) ;
32
+ feature_err( & visitor. sess. parse_sess, name, span, explain) . emit( ) ;
33
+ }
34
+ } } ;
35
+ ( future_incompatible; $visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => { {
36
+ let ( visitor, has_feature, span, name, explain) =
37
+ ( & * $visitor, $has_feature, $span, $name, $explain) ;
38
+ let has_feature: bool = has_feature( visitor. features) ;
39
+ debug!(
40
+ "gate_feature(feature = {:?}, span = {:?}); has? {} (future_incompatible)" ,
41
+ name, span, has_feature
42
+ ) ;
43
+ if !has_feature && !span. allows_unstable( $name) {
44
+ feature_warn( & visitor. sess. parse_sess, name, span, explain) ;
36
45
}
37
46
} } ;
38
47
}
@@ -44,6 +53,9 @@ macro_rules! gate_feature_post {
44
53
( $visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
45
54
gate_feature_fn!( $visitor, |x: & Features | x. $feature, $span, sym:: $feature, $explain)
46
55
} ;
56
+ ( future_incompatible; $visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
57
+ gate_feature_fn!( future_incompatible; $visitor, |x: & Features | x. $feature, $span, sym:: $feature, $explain)
58
+ } ;
47
59
}
48
60
49
61
pub fn check_attribute ( attr : & ast:: Attribute , sess : & Session , features : & Features ) {
@@ -588,11 +600,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
588
600
{
589
601
// When we encounter a statement of the form `foo: Ty = val;`, this will emit a type
590
602
// ascription error, but the likely intention was to write a `let` statement. (#78907).
591
- feature_err_issue (
603
+ feature_err (
592
604
& self . sess . parse_sess ,
593
605
sym:: type_ascription,
594
606
lhs. span ,
595
- GateIssue :: Language ,
596
607
"type ascription is experimental" ,
597
608
) . span_suggestion_verbose (
598
609
lhs. span . shrink_to_lo ( ) ,
@@ -615,15 +626,22 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
615
626
) ;
616
627
}
617
628
ast:: ExprKind :: Type ( ..) => {
618
- // To avoid noise about type ascription in common syntax errors, only emit if it
619
- // is the *only* error.
620
629
if self . sess . parse_sess . span_diagnostic . err_count ( ) == 0 {
630
+ // To avoid noise about type ascription in common syntax errors,
631
+ // only emit if it is the *only* error.
621
632
gate_feature_post ! (
622
633
& self ,
623
634
type_ascription,
624
635
e. span,
625
636
"type ascription is experimental"
626
637
) ;
638
+ } else {
639
+ // And if it isn't, cancel the early-pass warning.
640
+ self . sess
641
+ . parse_sess
642
+ . span_diagnostic
643
+ . steal_diagnostic ( e. span , StashKey :: EarlySyntaxWarning )
644
+ . map ( |err| err. cancel ( ) ) ;
627
645
}
628
646
}
629
647
ast:: ExprKind :: TryBlock ( _) => {
@@ -789,14 +807,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
789
807
790
808
// All uses of `gate_all!` below this point were added in #65742,
791
809
// and subsequently disabled (with the non-early gating readded).
810
+ // We emit an early future-incompatible warning for these.
811
+ // New syntax gates should go above here to get a hard error gate.
792
812
macro_rules! gate_all {
793
813
( $gate: ident, $msg: literal) => {
794
- // FIXME(eddyb) do something more useful than always
795
- // disabling these uses of early feature-gatings.
796
- if false {
797
- for span in spans. get( & sym:: $gate) . unwrap_or( & vec![ ] ) {
798
- gate_feature_post!( & visitor, $gate, * span, $msg) ;
799
- }
814
+ for span in spans. get( & sym:: $gate) . unwrap_or( & vec![ ] ) {
815
+ gate_feature_post!( future_incompatible; & visitor, $gate, * span, $msg) ;
800
816
}
801
817
} ;
802
818
}
@@ -809,11 +825,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
809
825
gate_all ! ( try_blocks, "`try` blocks are unstable" ) ;
810
826
gate_all ! ( label_break_value, "labels on blocks are unstable" ) ;
811
827
gate_all ! ( box_syntax, "box expression syntax is experimental; you can call `Box::new` instead" ) ;
812
- // To avoid noise about type ascription in common syntax errors,
813
- // only emit if it is the *only* error. (Also check it last.)
814
- if sess. parse_sess . span_diagnostic . err_count ( ) == 0 {
815
- gate_all ! ( type_ascription, "type ascription is experimental" ) ;
816
- }
828
+ gate_all ! ( type_ascription, "type ascription is experimental" ) ;
817
829
818
830
visit:: walk_crate ( & mut visitor, krate) ;
819
831
}
0 commit comments