Add feature gate

This commit is contained in:
Aaron Turon 2015-12-30 15:16:43 -08:00
parent 9f16c2ce59
commit e816910398
2 changed files with 22 additions and 0 deletions

View file

@ -88,6 +88,16 @@ impl SpecializationGraph {
let overlap = traits::overlapping_impls(&infcx, possible_sibling, impl_def_id);
if let Some(trait_ref) = overlap {
if !tcx.sess.features.borrow().specialization {
// if specialization is not turned on, all overlaps
// should immediately trigger an error
return Err(Overlap {
with_impl: possible_sibling,
on_trait_ref: trait_ref,
});
}
let le = specializes(tcx, impl_def_id, possible_sibling);
let ge = specializes(tcx, possible_sibling, impl_def_id);

View file

@ -248,6 +248,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
// `expr?`
("question_mark", "1.9.0", Some(31436), Active)
// impl specialization (RFC 1210)
("specialization", "1.7.0", None, Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
@ -574,6 +577,7 @@ pub struct Features {
pub stmt_expr_attributes: bool,
pub deprecated: bool,
pub question_mark: bool,
pub specialization: bool,
}
impl Features {
@ -608,6 +612,7 @@ impl Features {
stmt_expr_attributes: false,
deprecated: false,
question_mark: false,
specialization: false,
}
}
}
@ -1102,6 +1107,12 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
}
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
if ii.defaultness == ast::Defaultness::Default {
self.gate_feature("specialization",
ii.span,
"specialization is unstable");
}
match ii.node {
ast::ImplItemKind::Const(..) => {
self.gate_feature("associated_consts",
@ -1212,6 +1223,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
stmt_expr_attributes: cx.has_feature("stmt_expr_attributes"),
deprecated: cx.has_feature("deprecated"),
question_mark: cx.has_feature("question_mark"),
specialization: cx.has_feature("specialization"),
}
}