Skip to content

Commit 2571468

Browse files
committed
const_generics: abort on mising feature
1 parent f509b26 commit 2571468

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/librustc_ast_passes/feature_gate.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId};
22
use rustc_ast::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
33
use rustc_ast::attr;
44
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};
66
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
77
use rustc_feature::{Features, GateIssue, UnstableFeatures};
88
use rustc_session::parse::{feature_err, feature_err_issue, ParseSess};
@@ -13,19 +13,22 @@ use rustc_span::Span;
1313
use log::debug;
1414

1515
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 $(,)?)?) => {{
1717
let (cx, has_feature, span, name, explain) = (&*$cx, $has_feature, $span, $name, $explain);
1818
let has_feature: bool = has_feature(&$cx.features);
1919
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
2020
if !has_feature && !span.allows_unstable($name) {
2121
feature_err_issue(cx.parse_sess, name, span, GateIssue::Language, explain).emit();
22+
$(
23+
$fatal.raise();
24+
)?
2225
}
2326
}};
2427
}
2528

2629
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)?)
2932
};
3033
}
3134

@@ -517,12 +520,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
517520

518521
fn visit_generic_param(&mut self, param: &'a GenericParam) {
519522
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+
}
526535
_ => {}
527536
}
528537
visit::walk_generic_param(self, param)

0 commit comments

Comments
 (0)