Skip to content

Commit 934902a

Browse files
committed
Auto merge of #49252 - Manishearth:easy-feature-flag, r=nikomatsakis
Easy edition feature flag We no longer gate features on epochs; instead we have a `#![feature(rust_2018_preview)]` that flips on a bunch of features (currently dyn_trait). Based on #49001 to avoid merge conflicts r? @nikomatsakis
2 parents 097efa9 + 195c6b4 commit 934902a

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

src/libsyntax/edition.rs

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ impl Edition {
5555
Edition::Edition2018 => "edition_2018",
5656
}
5757
}
58+
59+
pub fn feature_name(&self) -> &'static str {
60+
match *self {
61+
Edition::Edition2015 => "rust_2015_preview",
62+
Edition::Edition2018 => "rust_2018_preview",
63+
}
64+
}
5865
}
5966

6067
impl FromStr for Edition {

src/libsyntax/feature_gate.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use self::AttributeGate::*;
2828
use abi::Abi;
2929
use ast::{self, NodeId, PatKind, RangeEnd};
3030
use attr;
31-
use edition::Edition;
31+
use edition::{ALL_EDITIONS, Edition};
3232
use codemap::Spanned;
3333
use syntax_pos::{Span, DUMMY_SP};
3434
use errors::{DiagnosticBuilder, Handler, FatalError};
@@ -1800,21 +1800,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18001800
}
18011801

18021802
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1803-
edition: Edition) -> Features {
1803+
crate_edition: Edition) -> Features {
1804+
fn feature_removed(span_handler: &Handler, span: Span) {
1805+
span_err!(span_handler, span, E0557, "feature has been removed");
1806+
}
1807+
18041808
let mut features = Features::new();
18051809

18061810
let mut feature_checker = FeatureChecker::default();
18071811

1808-
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1809-
if let Some(f_edition) = f_edition {
1810-
if edition >= f_edition {
1811-
// FIXME(Manishearth) there is currently no way to set
1812-
// lang features by edition
1813-
set(&mut features, DUMMY_SP);
1814-
}
1815-
}
1816-
}
1817-
18181812
for attr in krate_attrs {
18191813
if !attr.check_name("feature") {
18201814
continue
@@ -1827,6 +1821,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
18271821
}
18281822
Some(list) => {
18291823
for mi in list {
1824+
18301825
let name = if let Some(word) = mi.word() {
18311826
word.name()
18321827
} else {
@@ -1844,11 +1839,26 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
18441839
.find(|& &(n, _, _)| name == n)
18451840
.or_else(|| STABLE_REMOVED_FEATURES.iter()
18461841
.find(|& &(n, _, _)| name == n)) {
1847-
span_err!(span_handler, mi.span, E0557, "feature has been removed");
1842+
feature_removed(span_handler, mi.span);
18481843
}
18491844
else if let Some(&(_, _, _)) = ACCEPTED_FEATURES.iter()
18501845
.find(|& &(n, _, _)| name == n) {
18511846
features.declared_stable_lang_features.push((name, mi.span));
1847+
} else if let Some(&edition) = ALL_EDITIONS.iter()
1848+
.find(|e| name == e.feature_name()) {
1849+
if edition <= crate_edition {
1850+
feature_removed(span_handler, mi.span);
1851+
} else {
1852+
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1853+
if let Some(f_edition) = f_edition {
1854+
if edition >= f_edition {
1855+
// FIXME(Manishearth) there is currently no way to set
1856+
// lib features by edition
1857+
set(&mut features, DUMMY_SP);
1858+
}
1859+
}
1860+
}
1861+
}
18521862
} else {
18531863
features.declared_lib_features.push((name, mi.span));
18541864
}

src/test/run-pass/epoch-gate-feature.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Checks if the correct registers are being used to pass arguments
1212
// when the sysv64 ABI is specified.
1313

14-
// compile-flags: -Zedition=2018
14+
#![feature(rust_2018_preview)]
1515

1616
pub trait Foo {}
1717

0 commit comments

Comments
 (0)