Skip to content

Commit bce31ea

Browse files
committed
Add the -Zfeature=foo nightly flag to enable features from the CLI
1 parent 3616da7 commit bce31ea

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13511351
"generate build artifacts that are compatible with linker-based LTO."),
13521352
no_parallel_llvm: bool = (false, parse_bool, [UNTRACKED],
13531353
"don't run LLVM in parallel (while keeping codegen-units and ThinLTO)"),
1354+
feature: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
1355+
"enable the provided nightly feature (can be used multiple times)"),
13541356
}
13551357

13561358
pub fn default_lib_output() -> CrateType {

src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ where
812812
let (mut krate, features) = syntax::config::features(
813813
krate,
814814
&sess.parse_sess,
815+
&sess.opts.debugging_opts.feature,
815816
sess.opts.test,
816817
sess.edition(),
817818
);

src/libsyntax/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct StripUnconfigured<'a> {
2727
}
2828

2929
// `cfg_attr`-process the crate's attributes and compute the crate's features.
30-
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, edition: Edition)
31-
-> (ast::Crate, Features) {
30+
pub fn features(mut krate: ast::Crate, sess: &ParseSess, z_features: &[String], should_test: bool,
31+
edition: Edition) -> (ast::Crate, Features) {
3232
let features;
3333
{
3434
let mut strip_unconfigured = StripUnconfigured {
@@ -47,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, edit
4747
return (krate, Features::new());
4848
}
4949

50-
features = get_features(&sess.span_diagnostic, &krate.attrs, edition);
50+
features = get_features(&sess.span_diagnostic, &krate.attrs, &z_features, edition);
5151

5252
// Avoid reconfiguring malformed `cfg_attr`s
5353
if err_count == sess.span_diagnostic.err_count() {

src/libsyntax/feature_gate.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18891889
}
18901890
}
18911891

1892-
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1892+
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], z_features: &[String],
18931893
crate_edition: Edition) -> Features {
18941894
let mut features = Features::new();
18951895

@@ -1937,6 +1937,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19371937
}
19381938
}
19391939

1940+
for z_feature in z_features {
1941+
set_feature(
1942+
Symbol::intern(&z_feature),
1943+
DUMMY_SP,
1944+
span_handler,
1945+
&mut features,
1946+
&mut feature_checker,
1947+
crate_edition,
1948+
);
1949+
}
1950+
19401951
feature_checker.check(span_handler);
19411952

19421953
features

src/test/run-pass/z-feature.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// This test checks if an unstable feature is enabled with the -Zfeature=foo
12+
// flag. If the exact feature used here is causing problems feel free to
13+
// replace it with another perma-unstable feature.
14+
15+
// compile-flags: -Zfeature=abi_unadjusted
16+
17+
#![allow(dead_code)]
18+
19+
extern "unadjusted" fn foo() {}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)