Skip to content

Commit e816910

Browse files
committed
Add feature gate
1 parent 9f16c2c commit e816910

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc/middle/traits/specialize.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ impl SpecializationGraph {
8888
let overlap = traits::overlapping_impls(&infcx, possible_sibling, impl_def_id);
8989

9090
if let Some(trait_ref) = overlap {
91+
if !tcx.sess.features.borrow().specialization {
92+
// if specialization is not turned on, all overlaps
93+
// should immediately trigger an error
94+
95+
return Err(Overlap {
96+
with_impl: possible_sibling,
97+
on_trait_ref: trait_ref,
98+
});
99+
}
100+
91101
let le = specializes(tcx, impl_def_id, possible_sibling);
92102
let ge = specializes(tcx, possible_sibling, impl_def_id);
93103

src/libsyntax/feature_gate.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
248248

249249
// `expr?`
250250
("question_mark", "1.9.0", Some(31436), Active)
251+
252+
// impl specialization (RFC 1210)
253+
("specialization", "1.7.0", None, Active),
251254
];
252255
// (changing above list without updating src/doc/reference.md makes @cmr sad)
253256

@@ -574,6 +577,7 @@ pub struct Features {
574577
pub stmt_expr_attributes: bool,
575578
pub deprecated: bool,
576579
pub question_mark: bool,
580+
pub specialization: bool,
577581
}
578582

579583
impl Features {
@@ -608,6 +612,7 @@ impl Features {
608612
stmt_expr_attributes: false,
609613
deprecated: false,
610614
question_mark: false,
615+
specialization: false,
611616
}
612617
}
613618
}
@@ -1102,6 +1107,12 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
11021107
}
11031108

11041109
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
1110+
if ii.defaultness == ast::Defaultness::Default {
1111+
self.gate_feature("specialization",
1112+
ii.span,
1113+
"specialization is unstable");
1114+
}
1115+
11051116
match ii.node {
11061117
ast::ImplItemKind::Const(..) => {
11071118
self.gate_feature("associated_consts",
@@ -1212,6 +1223,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
12121223
stmt_expr_attributes: cx.has_feature("stmt_expr_attributes"),
12131224
deprecated: cx.has_feature("deprecated"),
12141225
question_mark: cx.has_feature("question_mark"),
1226+
specialization: cx.has_feature("specialization"),
12151227
}
12161228
}
12171229

0 commit comments

Comments
 (0)