From 33b6631d9b2c79c548a9abdaf585a230b5f14ad9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 1 May 2020 23:32:00 +0300 Subject: [PATCH] Enable `cfg` predicate for `target_feature = "crt-static"` only if the target supports it --- src/librustc_interface/util.rs | 2 +- src/librustc_session/session.rs | 11 +++-------- src/test/ui/crt-static-on-works.rs | 7 ++----- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index c5a4d28d151b3..64114fbd1c489 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -49,7 +49,7 @@ pub fn add_configuration( cfg.extend(codegen_backend.target_features(sess).into_iter().map(|feat| (tf, Some(feat)))); - if sess.crt_static_feature(None) { + if sess.crt_static(None) { cfg.insert((tf, Some(Symbol::intern("crt-static")))); } } diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs index 69e1b46de4df7..f85be218bc218 100644 --- a/src/librustc_session/session.rs +++ b/src/librustc_session/session.rs @@ -553,16 +553,11 @@ impl Session { /// Check whether this compile session and crate type use static crt. pub fn crt_static(&self, crate_type: Option) -> bool { - // If the target does not opt in to crt-static support, use its default. - if self.target.target.options.crt_static_respected { - self.crt_static_feature(crate_type) - } else { - self.target.target.options.crt_static_default + if !self.target.target.options.crt_static_respected { + // If the target does not opt in to crt-static support, use its default. + return self.target.target.options.crt_static_default; } - } - /// Check whether this compile session and crate type use `crt-static` feature. - pub fn crt_static_feature(&self, crate_type: Option) -> bool { let requested_features = self.opts.cg.target_feature.split(','); let found_negative = requested_features.clone().any(|r| r == "-crt-static"); let found_positive = requested_features.clone().any(|r| r == "+crt-static"); diff --git a/src/test/ui/crt-static-on-works.rs b/src/test/ui/crt-static-on-works.rs index 21407b1b9118c..f89d1edd6586a 100644 --- a/src/test/ui/crt-static-on-works.rs +++ b/src/test/ui/crt-static-on-works.rs @@ -1,9 +1,6 @@ // run-pass - -#![allow(stable_features)] -// compile-flags:-C target-feature=+crt-static -Z unstable-options - -#![feature(cfg_target_feature)] +// compile-flags:-C target-feature=+crt-static +// only-msvc #[cfg(target_feature = "crt-static")] fn main() {}