Skip to content

Commit 2885632

Browse files
alexcrichtonMark-Simulacrum
authored andcommitted
rustc: Allow an edition's feature on that edition
This commit fixes a hard error where the `#![feature(rust_2018_preview)]` feature was forbidden to be mentioned when the `--edition 2018` flag was passed. This instead silently accepts that feature gate despite it not being necessary. It's intended that this will help ease the transition into the 2018 edition as users will, for the time being, start off with the `rust_2018_preview` feature and no longer immediately need to remove it. Closes #50662
1 parent bd44177 commit 2885632

File tree

2 files changed

+62
-41
lines changed

2 files changed

+62
-41
lines changed

src/libsyntax/feature_gate.rs

+46-41
Original file line numberDiff line numberDiff line change
@@ -1861,56 +1861,61 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
18611861
continue
18621862
}
18631863

1864-
match attr.meta_item_list() {
1864+
let list = match attr.meta_item_list() {
1865+
Some(list) => list,
18651866
None => {
18661867
span_err!(span_handler, attr.span, E0555,
18671868
"malformed feature attribute, expected #![feature(...)]");
1869+
continue
1870+
}
1871+
};
1872+
1873+
for mi in list {
1874+
let name = if let Some(word) = mi.word() {
1875+
word.name()
1876+
} else {
1877+
span_err!(span_handler, mi.span, E0556,
1878+
"malformed feature, expected just one word");
1879+
continue
1880+
};
1881+
1882+
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
1883+
set(&mut features, mi.span);
1884+
feature_checker.collect(&features, mi.span);
1885+
continue
18681886
}
1869-
Some(list) => {
1870-
for mi in list {
18711887

1872-
let name = if let Some(word) = mi.word() {
1873-
word.name()
1874-
} else {
1875-
span_err!(span_handler, mi.span, E0556,
1876-
"malformed feature, expected just one word");
1877-
continue
1878-
};
1879-
1880-
if let Some(&(_, _, _, _, set)) = ACTIVE_FEATURES.iter()
1881-
.find(|& &(n, ..)| name == n) {
1882-
set(&mut features, mi.span);
1883-
feature_checker.collect(&features, mi.span);
1884-
}
1885-
else if let Some(&(.., reason)) = REMOVED_FEATURES.iter()
1886-
.find(|& &(n, ..)| name == n)
1887-
.or_else(|| STABLE_REMOVED_FEATURES.iter()
1888-
.find(|& &(n, ..)| name == n)) {
1889-
feature_removed(span_handler, mi.span, reason);
1890-
}
1891-
else if let Some(&(..)) = ACCEPTED_FEATURES.iter()
1892-
.find(|& &(n, ..)| name == n) {
1893-
features.declared_stable_lang_features.push((name, mi.span));
1894-
} else if let Some(&edition) = ALL_EDITIONS.iter()
1895-
.find(|e| name == e.feature_name()) {
1896-
if edition <= crate_edition {
1897-
feature_removed(span_handler, mi.span, None);
1898-
} else {
1899-
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1900-
if let Some(f_edition) = f_edition {
1901-
if edition >= f_edition {
1902-
// FIXME(Manishearth) there is currently no way to set
1903-
// lib features by edition
1904-
set(&mut features, DUMMY_SP);
1905-
}
1906-
}
1907-
}
1888+
let removed = REMOVED_FEATURES.iter().find(|f| name == f.0);
1889+
let stable_removed = STABLE_REMOVED_FEATURES.iter().find(|f| name == f.0);
1890+
if let Some((.., reason)) = removed.or(stable_removed) {
1891+
feature_removed(span_handler, mi.span, *reason);
1892+
continue
1893+
}
1894+
1895+
if ACCEPTED_FEATURES.iter().any(|f| name == f.0) {
1896+
features.declared_stable_lang_features.push((name, mi.span));
1897+
continue
1898+
}
1899+
1900+
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
1901+
if *edition <= crate_edition {
1902+
continue
1903+
}
1904+
1905+
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1906+
if let Some(f_edition) = f_edition {
1907+
if *edition >= f_edition {
1908+
// FIXME(Manishearth) there is currently no way to set
1909+
// lib features by edition
1910+
set(&mut features, DUMMY_SP);
19081911
}
1909-
} else {
1910-
features.declared_lib_features.push((name, mi.span));
19111912
}
19121913
}
1914+
1915+
continue
19131916
}
1917+
1918+
features.declared_lib_features.push((name, mi.span));
19141919
}
19151920
}
19161921

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--edition 2018
12+
// compile-pass
13+
14+
#![feature(rust_2018_preview)]
15+
16+
fn main() {}

0 commit comments

Comments
 (0)