Skip to content

Commit a133caa

Browse files
authored
Rollup merge of #60289 - tmandry:allow-features-include-std, r=cramertj
Make `-Z allow-features` work for stdlib features r? @cramertj
2 parents 6664534 + 0a26789 commit a133caa

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
@@ -2259,32 +2259,32 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
22592259
continue;
22602260
}
22612261

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

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

22902290
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)