Skip to content

Commit d4754ed

Browse files
authored
Rollup merge of #108949 - Urgau:check-cfg-target-json, r=oli-obk
Honor current target when checking conditional compilation values This is fixed by simply using the currently registered target in the current session. We need to use it because of target json that are not by de#cluded in the rustc list of targets. Fixes #108941
2 parents 5e52ada + 3455d66 commit d4754ed

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

Diff for: compiler/rustc_interface/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn create_session(
110110
add_configuration(&mut cfg, &mut sess, &*codegen_backend);
111111

112112
let mut check_cfg = config::to_crate_check_config(check_cfg);
113-
check_cfg.fill_well_known();
113+
check_cfg.fill_well_known(&sess.target);
114114

115115
sess.parse_sess.config = cfg;
116116
sess.parse_sess.check_config = check_cfg;

Diff for: compiler/rustc_session/src/config.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ impl CrateCheckConfig {
11371137
}
11381138

11391139
/// Fills a `CrateCheckConfig` with well-known configuration values.
1140-
fn fill_well_known_values(&mut self) {
1140+
fn fill_well_known_values(&mut self, current_target: &Target) {
11411141
if !self.well_known_values {
11421142
return;
11431143
}
@@ -1229,6 +1229,7 @@ impl CrateCheckConfig {
12291229
for target in TARGETS
12301230
.iter()
12311231
.map(|target| Target::expect_builtin(&TargetTriple::from_triple(target)))
1232+
.chain(iter::once(current_target.clone()))
12321233
{
12331234
values_target_os.insert(Symbol::intern(&target.options.os));
12341235
values_target_family
@@ -1243,9 +1244,9 @@ impl CrateCheckConfig {
12431244
}
12441245
}
12451246

1246-
pub fn fill_well_known(&mut self) {
1247+
pub fn fill_well_known(&mut self, current_target: &Target) {
12471248
self.fill_well_known_names();
1248-
self.fill_well_known_values();
1249+
self.fill_well_known_values(current_target);
12491250
}
12501251
}
12511252

Diff for: tests/ui/check-cfg/my-awesome-platform.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"llvm-target": "x86_64-unknown-none-gnu",
3+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
4+
"arch": "x86_64",
5+
"target-endian": "little",
6+
"target-pointer-width": "64",
7+
"target-c-int-width": "32",
8+
"os": "ericos",
9+
"linker-flavor": "ld.lld",
10+
"linker": "rust-lld",
11+
"executables": true
12+
}

Diff for: tests/ui/check-cfg/values-target-json.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This test checks that we don't lint values defined by a custom target (target json)
2+
//
3+
// check-pass
4+
// needs-llvm-components: x86
5+
// compile-flags: --crate-type=lib --check-cfg=values() --target={{src-base}}/check-cfg/my-awesome-platform.json -Z unstable-options
6+
7+
#![feature(lang_items, no_core, auto_traits)]
8+
#![no_core]
9+
10+
#[lang = "sized"]
11+
trait Sized {}
12+
13+
#[cfg(target_os = "linuz")]
14+
//~^ WARNING unexpected `cfg` condition value
15+
fn target_os_linux_misspell() {}
16+
17+
#[cfg(target_os = "linux")]
18+
fn target_os_linux() {}
19+
20+
#[cfg(target_os = "ericos")]
21+
fn target_os_ericos() {}

Diff for: tests/ui/check-cfg/values-target-json.stderr

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: unexpected `cfg` condition value
2+
--> $DIR/values-target-json.rs:13:7
3+
|
4+
LL | #[cfg(target_os = "linuz")]
5+
| ^^^^^^^^^^^^-------
6+
| |
7+
| help: did you mean: `"linux"`
8+
|
9+
= note: expected values for `target_os` are: aix, android, cuda, dragonfly, emscripten, ericos, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vita, vxworks, wasi, watchos, windows, xous
10+
= note: `#[warn(unexpected_cfgs)]` on by default
11+
12+
warning: 1 warning emitted
13+

0 commit comments

Comments
 (0)