Skip to content

Commit 0f00979

Browse files
committed
syntax: process all edition features before other features.
1 parent d767ee1 commit 0f00979

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19231923
let mut features = Features::new();
19241924
let mut edition_enabled_features = FxHashMap();
19251925

1926-
for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() {
1926+
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
19271927
if let Some(f_edition) = f_edition {
19281928
if f_edition <= crate_edition {
19291929
set(&mut features, DUMMY_SP);
@@ -1932,35 +1932,31 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19321932
}
19331933
}
19341934

1935+
// Process the edition umbrella feature-gates first, to ensure
1936+
// `edition_enabled_features` is completed before it's queried.
19351937
for attr in krate_attrs {
19361938
if !attr.check_name("feature") {
19371939
continue
19381940
}
19391941

19401942
let list = match attr.meta_item_list() {
19411943
Some(list) => list,
1942-
None => {
1943-
span_err!(span_handler, attr.span, E0555,
1944-
"malformed feature attribute, expected #![feature(...)]");
1945-
continue
1946-
}
1944+
None => continue,
19471945
};
19481946

19491947
for mi in list {
19501948
let name = if let Some(word) = mi.word() {
19511949
word.name()
19521950
} else {
1953-
span_err!(span_handler, mi.span, E0556,
1954-
"malformed feature, expected just one word");
19551951
continue
19561952
};
19571953

19581954
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
19591955
if *edition <= crate_edition {
1960-
continue
1956+
continue;
19611957
}
19621958

1963-
for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() {
1959+
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
19641960
if let Some(f_edition) = f_edition {
19651961
if f_edition <= *edition {
19661962
// FIXME(Manishearth) there is currently no way to set
@@ -1970,8 +1966,36 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19701966
}
19711967
}
19721968
}
1969+
}
1970+
}
1971+
}
1972+
1973+
for attr in krate_attrs {
1974+
if !attr.check_name("feature") {
1975+
continue
1976+
}
1977+
1978+
let list = match attr.meta_item_list() {
1979+
Some(list) => list,
1980+
None => {
1981+
span_err!(span_handler, attr.span, E0555,
1982+
"malformed feature attribute, expected #![feature(...)]");
1983+
continue
1984+
}
1985+
};
19731986

1987+
for mi in list {
1988+
let name = if let Some(word) = mi.word() {
1989+
word.name()
1990+
} else {
1991+
span_err!(span_handler, mi.span, E0556,
1992+
"malformed feature, expected just one word");
19741993
continue
1994+
};
1995+
1996+
if ALL_EDITIONS.iter().any(|e| name == e.feature_name()) {
1997+
// Handled in the separate loop above.
1998+
continue;
19751999
}
19762000

19772001
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {

src/test/ui/E0705.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
// compile-pass
1212

13-
#![feature(rust_2018_preview)]
1413
#![feature(raw_identifiers)]
1514
//~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition
15+
#![feature(rust_2018_preview)]
1616

1717
fn main() {
1818
let foo = 0;

src/test/ui/E0705.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition
2-
--> $DIR/E0705.rs:14:12
2+
--> $DIR/E0705.rs:13:12
33
|
44
LL | #![feature(raw_identifiers)]
55
| ^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)