Skip to content

Commit b7a04e0

Browse files
committed
Add feature gate for const generics
1 parent 390ee7f commit b7a04e0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/libsyntax/ast.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,8 @@ impl fmt::Display for ParamKindOrd {
323323
pub enum GenericParamKind {
324324
/// A lifetime definition, e.g. `'a: 'b+'c+'d`.
325325
Lifetime,
326-
Type {
327-
default: Option<P<Ty>>,
328-
},
329-
Const {
330-
ty: P<Ty>,
331-
},
326+
Type { default: Option<P<Ty>> },
327+
Const { ty: P<Ty> },
332328
}
333329

334330
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

src/libsyntax/feature_gate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use self::AttributeGate::*;
2727

2828
use rustc_data_structures::fx::FxHashMap;
2929
use rustc_target::spec::abi::Abi;
30-
use ast::{self, NodeId, PatKind, RangeEnd};
30+
use ast::{self, NodeId, PatKind, RangeEnd, GenericParam, GenericParamKind};
3131
use attr;
3232
use source_map::Spanned;
3333
use edition::{ALL_EDITIONS, Edition};
@@ -429,6 +429,9 @@ declare_features! (
429429
// `existential type`
430430
(active, existential_type, "1.28.0", Some(34511), None),
431431

432+
// const generic types
433+
(active, const_generics, "1.29.0", Some(44580), None),
434+
432435
// unstable #[target_feature] directives
433436
(active, arm_target_feature, "1.27.0", Some(44839), None),
434437
(active, aarch64_target_feature, "1.27.0", Some(44839), None),
@@ -1818,6 +1821,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18181821
visit::walk_fn(self, fn_kind, fn_decl, span);
18191822
}
18201823

1824+
fn visit_generic_param(&mut self, param: &'a GenericParam) {
1825+
if let GenericParamKind::Const { .. } = param.kind {
1826+
gate_feature_post!(&self, const_generics, param.ident.span,
1827+
"const generics are unstable");
1828+
}
1829+
visit::walk_generic_param(self, param);
1830+
}
1831+
18211832
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
18221833
match ti.node {
18231834
ast::TraitItemKind::Method(ref sig, ref block) => {

0 commit comments

Comments
 (0)