Skip to content

Commit 0a26789

Browse files
committed
Make -Z allow-features work for stdlib features
1 parent bd31c39 commit 0a26789

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

src/libsyntax/feature_gate.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -2258,32 +2258,32 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
22582258
continue;
22592259
}
22602260

2261-
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
2262-
if let Some(allowed) = allow_features.as_ref() {
2263-
if allowed.iter().find(|f| *f == name.as_str()).is_none() {
2264-
span_err!(span_handler, mi.span(), E0725,
2265-
"the feature `{}` is not in the list of allowed features",
2266-
name);
2267-
continue;
2268-
}
2269-
}
2270-
2271-
set(&mut features, mi.span());
2272-
features.declared_lang_features.push((name, mi.span(), None));
2273-
continue
2274-
}
2275-
22762261
let removed = REMOVED_FEATURES.iter().find(|f| name == f.0);
22772262
let stable_removed = STABLE_REMOVED_FEATURES.iter().find(|f| name == f.0);
22782263
if let Some((.., reason)) = removed.or(stable_removed) {
22792264
feature_removed(span_handler, mi.span(), *reason);
2280-
continue
2265+
continue;
22812266
}
22822267

22832268
if let Some((_, since, ..)) = ACCEPTED_FEATURES.iter().find(|f| name == f.0) {
22842269
let since = Some(Symbol::intern(since));
22852270
features.declared_lang_features.push((name, mi.span(), since));
2286-
continue
2271+
continue;
2272+
}
2273+
2274+
if let Some(allowed) = allow_features.as_ref() {
2275+
if allowed.iter().find(|f| *f == name.as_str()).is_none() {
2276+
span_err!(span_handler, mi.span(), E0725,
2277+
"the feature `{}` is not in the list of allowed features",
2278+
name);
2279+
continue;
2280+
}
2281+
}
2282+
2283+
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
2284+
set(&mut features, mi.span());
2285+
features.declared_lang_features.push((name, mi.span(), None));
2286+
continue;
22872287
}
22882288

22892289
features.declared_lib_features.push((name, mi.span()));

src/test/ui/feature-gate/allow-features-empty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77

88
#![feature(lang_items)] //~ ERROR
99

10+
#![feature(unknown_stdlib_feature)] //~ ERROR
11+
1012
fn main() {}

src/test/ui/feature-gate/allow-features-empty.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ error[E0725]: the feature `lang_items` is not in the list of allowed features
1616
LL | #![feature(lang_items)]
1717
| ^^^^^^^^^^
1818

19-
error: aborting due to 3 previous errors
19+
error[E0725]: the feature `unknown_stdlib_feature` is not in the list of allowed features
20+
--> $DIR/allow-features-empty.rs:10:12
21+
|
22+
LL | #![feature(unknown_stdlib_feature)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
2026

2127
For more information about this error, try `rustc --explain E0725`.

src/test/ui/feature-gate/allow-features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77

88
#![feature(lang_items)]
99

10+
#![feature(unknown_stdlib_feature)] //~ ERROR
11+
1012
fn main() {}

src/test/ui/feature-gate/allow-features.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ error[E0725]: the feature `rustc_const_unstable` is not in the list of allowed f
44
LL | #![feature(rustc_const_unstable)]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error[E0725]: the feature `unknown_stdlib_feature` is not in the list of allowed features
8+
--> $DIR/allow-features.rs:10:12
9+
|
10+
LL | #![feature(unknown_stdlib_feature)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
814

915
For more information about this error, try `rustc --explain E0725`.

0 commit comments

Comments
 (0)