Add easy edition feature flag
This commit is contained in:
parent
c08480fce0
commit
b70cc53804
2 changed files with 30 additions and 13 deletions
|
@ -55,6 +55,13 @@ impl Edition {
|
||||||
Edition::Edition2018 => "edition_2018",
|
Edition::Edition2018 => "edition_2018",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn feature_name(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
Edition::Edition2015 => "rust_2015_preview",
|
||||||
|
Edition::Edition2018 => "rust_2018_preview",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Edition {
|
impl FromStr for Edition {
|
||||||
|
|
|
@ -28,7 +28,7 @@ use self::AttributeGate::*;
|
||||||
use abi::Abi;
|
use abi::Abi;
|
||||||
use ast::{self, NodeId, PatKind, RangeEnd};
|
use ast::{self, NodeId, PatKind, RangeEnd};
|
||||||
use attr;
|
use attr;
|
||||||
use edition::Edition;
|
use edition::{ALL_EDITIONS, Edition};
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use errors::{DiagnosticBuilder, Handler, FatalError};
|
use errors::{DiagnosticBuilder, Handler, FatalError};
|
||||||
|
@ -1818,21 +1818,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
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 features = Features::new();
|
||||||
|
|
||||||
let mut feature_checker = FeatureChecker::default();
|
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 {
|
for attr in krate_attrs {
|
||||||
if !attr.check_name("feature") {
|
if !attr.check_name("feature") {
|
||||||
continue
|
continue
|
||||||
|
@ -1845,6 +1839,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||||
}
|
}
|
||||||
Some(list) => {
|
Some(list) => {
|
||||||
for mi in list {
|
for mi in list {
|
||||||
|
|
||||||
let name = if let Some(word) = mi.word() {
|
let name = if let Some(word) = mi.word() {
|
||||||
word.name()
|
word.name()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1862,11 +1857,26 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||||
.find(|& &(n, _, _)| name == n)
|
.find(|& &(n, _, _)| name == n)
|
||||||
.or_else(|| STABLE_REMOVED_FEATURES.iter()
|
.or_else(|| STABLE_REMOVED_FEATURES.iter()
|
||||||
.find(|& &(n, _, _)| name == n)) {
|
.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()
|
else if let Some(&(_, _, _)) = ACCEPTED_FEATURES.iter()
|
||||||
.find(|& &(n, _, _)| name == n) {
|
.find(|& &(n, _, _)| name == n) {
|
||||||
features.declared_stable_lang_features.push((name, mi.span));
|
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
|
||||||
|
// lib features by edition
|
||||||
|
set(&mut features, DUMMY_SP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
features.declared_lib_features.push((name, mi.span));
|
features.declared_lib_features.push((name, mi.span));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue