@@ -2,7 +2,7 @@ use rustc_ast::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId};
2
2
use rustc_ast:: ast:: { GenericParam , GenericParamKind , PatKind , RangeEnd , VariantData } ;
3
3
use rustc_ast:: attr;
4
4
use rustc_ast:: visit:: { self , AssocCtxt , FnCtxt , FnKind , Visitor } ;
5
- use rustc_errors:: { struct_span_err, Handler } ;
5
+ use rustc_errors:: { struct_span_err, FatalError , Handler } ;
6
6
use rustc_feature:: { AttributeGate , BUILTIN_ATTRIBUTE_MAP } ;
7
7
use rustc_feature:: { Features , GateIssue , UnstableFeatures } ;
8
8
use rustc_session:: parse:: { feature_err, feature_err_issue, ParseSess } ;
@@ -13,19 +13,22 @@ use rustc_span::Span;
13
13
use log:: debug;
14
14
15
15
macro_rules! gate_feature_fn {
16
- ( $cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => { {
16
+ ( $cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr $ ( , $fatal : expr $ ( , ) ? ) ? ) => { {
17
17
let ( cx, has_feature, span, name, explain) = ( & * $cx, $has_feature, $span, $name, $explain) ;
18
18
let has_feature: bool = has_feature( & $cx. features) ;
19
19
debug!( "gate_feature(feature = {:?}, span = {:?}); has? {}" , name, span, has_feature) ;
20
20
if !has_feature && !span. allows_unstable( $name) {
21
21
feature_err_issue( cx. parse_sess, name, span, GateIssue :: Language , explain) . emit( ) ;
22
+ $(
23
+ $fatal. raise( ) ;
24
+ ) ?
22
25
}
23
26
} } ;
24
27
}
25
28
26
29
macro_rules! gate_feature_post {
27
- ( $cx: expr, $feature: ident, $span: expr, $explain: expr) => {
28
- gate_feature_fn!( $cx, |x: & Features | x. $feature, $span, sym:: $feature, $explain)
30
+ ( $cx: expr, $feature: ident, $span: expr, $explain: expr $ ( , $fatal : expr $ ( , ) ? ) ? ) => {
31
+ gate_feature_fn!( $cx, |x: & Features | x. $feature, $span, sym:: $feature, $explain $ ( , $fatal ) ? )
29
32
} ;
30
33
}
31
34
@@ -517,12 +520,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
517
520
518
521
fn visit_generic_param ( & mut self , param : & ' a GenericParam ) {
519
522
match param. kind {
520
- GenericParamKind :: Const { .. } => gate_feature_post ! (
521
- & self ,
522
- const_generics,
523
- param. ident. span,
524
- "const generics are unstable"
525
- ) ,
523
+ GenericParamKind :: Const { .. } => {
524
+ // FIXME(const_generics): we currently stop compilation prematurely in case a
525
+ // generic param is found in locations where the `const_generics`
526
+ // feature is required.
527
+ gate_feature_post ! (
528
+ & self ,
529
+ const_generics,
530
+ param. ident. span,
531
+ "const generics are unstable" ,
532
+ FatalError ,
533
+ ) ;
534
+ }
526
535
_ => { }
527
536
}
528
537
visit:: walk_generic_param ( self , param)
0 commit comments