Skip to content

Commit a373b84

Browse files
authored
Auto merge of #33363 - japaric:target, r=japaric
fix built-in target detection previously the logic was accepting wrong triples (like `x86_64_unknown-linux-musl`) as valid ones (like `x86_64-unknown-linux-musl`) if they contained an underscore instead of a dash. fixes #33329 --- r? @brson I wanted to use a compile-fail test at first. But, you can't pass an extra `--target` flag to `rustc` for those because they already call `rustc --target $HOST` so you get a `error: Option 'target' given more than once.`. The run-make test used here works fine though.
2 parents 422ebd5 + f438801 commit a373b84

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/librustc_back/target/mod.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,18 @@ macro_rules! supported_targets {
7070
/// List of supported targets
7171
pub const TARGETS: &'static [&'static str] = &[$($triple),*];
7272

73-
// this would use a match if stringify! were allowed in pattern position
7473
fn load_specific(target: &str) -> Option<Target> {
75-
let target = target.replace("-", "_");
76-
if false { }
77-
$(
78-
else if target == stringify!($module) {
79-
let mut t = $module::target();
80-
t.options.is_builtin = true;
81-
debug!("Got builtin target: {:?}", t);
82-
return Some(t);
83-
}
84-
)*
85-
86-
None
74+
match target {
75+
$(
76+
$triple => {
77+
let mut t = $module::target();
78+
t.options.is_builtin = true;
79+
debug!("Got builtin target: {:?}", t);
80+
Some(t)
81+
},
82+
)+
83+
_ => None
84+
}
8785
}
8886
)
8987
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) --target x86_64_unknown-linux-musl main.rs 2>&1 | \
5+
grep "error: Error loading target specification: Could not find specification for target"

src/test/run-make/issue-33329/main.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2016 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+
fn main() {}

0 commit comments

Comments
 (0)