Skip to content

Commit

Permalink
Make -Z allow-features work for stdlib features
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Apr 25, 2019
1 parent bd31c39 commit 0a26789
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
34 changes: 17 additions & 17 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,32 +2258,32 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
continue;
}

if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
if let Some(allowed) = allow_features.as_ref() {
if allowed.iter().find(|f| *f == name.as_str()).is_none() {
span_err!(span_handler, mi.span(), E0725,
"the feature `{}` is not in the list of allowed features",
name);
continue;
}
}

set(&mut features, mi.span());
features.declared_lang_features.push((name, mi.span(), None));
continue
}

let removed = REMOVED_FEATURES.iter().find(|f| name == f.0);
let stable_removed = STABLE_REMOVED_FEATURES.iter().find(|f| name == f.0);
if let Some((.., reason)) = removed.or(stable_removed) {
feature_removed(span_handler, mi.span(), *reason);
continue
continue;
}

if let Some((_, since, ..)) = ACCEPTED_FEATURES.iter().find(|f| name == f.0) {
let since = Some(Symbol::intern(since));
features.declared_lang_features.push((name, mi.span(), since));
continue
continue;
}

if let Some(allowed) = allow_features.as_ref() {
if allowed.iter().find(|f| *f == name.as_str()).is_none() {
span_err!(span_handler, mi.span(), E0725,
"the feature `{}` is not in the list of allowed features",
name);
continue;
}
}

if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
set(&mut features, mi.span());
features.declared_lang_features.push((name, mi.span(), None));
continue;
}

features.declared_lib_features.push((name, mi.span()));
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/feature-gate/allow-features-empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

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

#![feature(unknown_stdlib_feature)] //~ ERROR

fn main() {}
8 changes: 7 additions & 1 deletion src/test/ui/feature-gate/allow-features-empty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ error[E0725]: the feature `lang_items` is not in the list of allowed features
LL | #![feature(lang_items)]
| ^^^^^^^^^^

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

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0725`.
2 changes: 2 additions & 0 deletions src/test/ui/feature-gate/allow-features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

#![feature(lang_items)]

#![feature(unknown_stdlib_feature)] //~ ERROR

fn main() {}
8 changes: 7 additions & 1 deletion src/test/ui/feature-gate/allow-features.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ error[E0725]: the feature `rustc_const_unstable` is not in the list of allowed f
LL | #![feature(rustc_const_unstable)]
| ^^^^^^^^^^^^^^^^^^^^

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

error: aborting due to 2 previous errors

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

0 comments on commit 0a26789

Please sign in to comment.