From 01daf90d5dea94e99dd4b5de57028024d3445d38 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Sun, 14 Feb 2016 23:09:44 +0100 Subject: [PATCH 1/3] Add usage documentation for `--print cfg` The `--print` flag was extended in #31278 to accept `cfg`, but the usage message was not updated. --- src/librustc/session/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index ea08bf021fbba..679da4abf5f9f 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -887,7 +887,7 @@ pub fn rustc_short_optgroups() -> Vec { "[asm|llvm-bc|llvm-ir|obj|link|dep-info]"), opt::multi_s("", "print", "Comma separated list of compiler information to \ print on stdout", - "[crate-name|file-names|sysroot|target-list]"), + "[crate-name|file-names|sysroot|cfg|target-list]"), opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"), opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"), opt::opt_s("o", "", "Write output to ", "FILENAME"), From c984cbd9397562f58d654a639923f16569b393ba Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Wed, 2 Mar 2016 22:07:03 +0100 Subject: [PATCH 2/3] Build the same configuration when compiling and for `--print cfg` The configuration returned by `config::build_configuration` needs to be modified with `target_features::add_configuration` in order to also contain the target features. This is already done for the configuration used when compiling and when creating the documentation, but was missing in the `cfg` printing code. --- src/librustc_driver/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index d0f86cfcb46ba..0a3ebcb4ca1eb 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -565,7 +565,9 @@ impl RustcDefaultCalls { } } PrintRequest::Cfg => { - for cfg in config::build_configuration(sess) { + let mut cfg = config::build_configuration(&sess); + target_features::add_configuration(&mut cfg, &sess); + for cfg in cfg { match cfg.node { ast::MetaItemKind::Word(ref word) => println!("{}", word), ast::MetaItemKind::NameValue(ref name, ref value) => { From 4e46eee110b739ab415affc8f9b524d6b4be8554 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Thu, 3 Mar 2016 10:06:09 +0100 Subject: [PATCH 3/3] Hide gated cfg attributes from the output of `--print cfg` Gated cfg attributes are not available on the stable and beta release channels, therefore they should not be presented to users of those channels in order to avoid confusion. --- src/librustc_driver/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 0a3ebcb4ca1eb..da565856a9f5a 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -94,7 +94,7 @@ use syntax::errors; use syntax::errors::emitter::Emitter; use syntax::diagnostics; use syntax::parse::token; -use syntax::feature_gate::UnstableFeatures; +use syntax::feature_gate::{GatedCfg, UnstableFeatures}; #[cfg(test)] pub mod test; @@ -567,7 +567,16 @@ impl RustcDefaultCalls { PrintRequest::Cfg => { let mut cfg = config::build_configuration(&sess); target_features::add_configuration(&mut cfg, &sess); + + let allow_unstable_cfg = match get_unstable_features_setting() { + UnstableFeatures::Disallow => false, + _ => true, + }; + for cfg in cfg { + if !allow_unstable_cfg && GatedCfg::gate(&*cfg).is_some() { + continue; + } match cfg.node { ast::MetaItemKind::Word(ref word) => println!("{}", word), ast::MetaItemKind::NameValue(ref name, ref value) => {