Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy edition feature flag #49252

Merged
merged 2 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libsyntax/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ impl Edition {
Edition::Edition2018 => "edition_2018",
}
}

pub fn feature_name(&self) -> &'static str {
match *self {
Edition::Edition2015 => "rust_2015_preview",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding the anachronism of "preview" may be more valuable than keeping these names symmetrical?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, once a feature is added it can't be "removed" completely.

There's no way to use the rust_2015_preview feature, that feature exists only so that attempting to use it will throw a "feature removed" warning. This goes for the 2018_preview feature when you enable the 2018 epoch, as well.

Yes, we could just not do this for 2015, but it didn't seem worth it to special case 2015.

Edition::Edition2018 => "rust_2018_preview",
}
}
}

impl FromStr for Edition {
Expand Down
36 changes: 23 additions & 13 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use self::AttributeGate::*;
use abi::Abi;
use ast::{self, NodeId, PatKind, RangeEnd};
use attr;
use edition::Edition;
use edition::{ALL_EDITIONS, Edition};
use codemap::Spanned;
use syntax_pos::{Span, DUMMY_SP};
use errors::{DiagnosticBuilder, Handler, FatalError};
Expand Down Expand Up @@ -1818,21 +1818,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
edition: Edition) -> Features {
crate_edition: Edition) -> Features {
fn feature_removed(span_handler: &Handler, span: Span) {
span_err!(span_handler, span, E0557, "feature has been removed");
}

let mut features = Features::new();

let mut feature_checker = FeatureChecker::default();

for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
if let Some(f_edition) = f_edition {
if edition >= f_edition {
// FIXME(Manishearth) there is currently no way to set
// lang features by edition
set(&mut features, DUMMY_SP);
}
}
}

for attr in krate_attrs {
if !attr.check_name("feature") {
continue
Expand All @@ -1845,6 +1839,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
}
Some(list) => {
for mi in list {

let name = if let Some(word) = mi.word() {
word.name()
} else {
Expand All @@ -1862,11 +1857,26 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
.find(|& &(n, _, _)| name == n)
.or_else(|| STABLE_REMOVED_FEATURES.iter()
.find(|& &(n, _, _)| name == n)) {
span_err!(span_handler, mi.span, E0557, "feature has been removed");
feature_removed(span_handler, mi.span);
}
else if let Some(&(_, _, _)) = ACCEPTED_FEATURES.iter()
.find(|& &(n, _, _)| name == n) {
features.declared_stable_lang_features.push((name, mi.span));
} else if let Some(&edition) = ALL_EDITIONS.iter()
.find(|e| name == e.feature_name()) {
if edition <= crate_edition {
feature_removed(span_handler, mi.span);
} else {
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
if let Some(f_edition) = f_edition {
if edition >= f_edition {
// FIXME(Manishearth) there is currently no way to set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean libs? :)

// lib features by edition
set(&mut features, DUMMY_SP);
}
}
}
}
} else {
features.declared_lib_features.push((name, mi.span));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/epoch-gate-feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Checks if the correct registers are being used to pass arguments
// when the sysv64 ABI is specified.

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

pub trait Foo {}

Expand Down