Skip to content

Commit 2c034e9

Browse files
committed
only stabilize -Clink-self-contained=-linker on x64 linux
Some combinations of opt-ins and other flags need more work to be stabilized, so we can only stabilize the opt-outs.
1 parent 0033c13 commit 2c034e9

14 files changed

+45
-46
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,28 +377,22 @@ impl LinkSelfContained {
377377
return Ok(());
378378
}
379379

380-
// `-C link-self-contained=[-+]linker` is only stable on x64 linux.
381-
let check_linker = |components: LinkSelfContainedComponents, polarity: &str| {
382-
let has_linker = components.is_linker_enabled();
383-
if has_linker && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
384-
return Err(format!(
385-
"`-C link-self-contained={polarity}linker` is unstable on the `{target_tuple}` \
380+
// `-C link-self-contained=-linker` is only stable on x64 linux.
381+
let has_minus_linker = self.disabled_components.is_linker_enabled();
382+
if has_minus_linker && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
383+
return Err(format!(
384+
"`-C link-self-contained=-linker` is unstable on the `{target_tuple}` \
386385
target. The `-Z unstable-options` flag must also be passed to use it on this target",
387-
));
388-
}
389-
Ok(())
390-
};
391-
check_linker(self.enabled_components, "+")?;
392-
check_linker(self.disabled_components, "-")?;
386+
));
387+
}
393388

394-
// Since only the linker component is stable, any other component used is unstable, and
395-
// that's an error.
396-
let unstable_enabled = self.enabled_components - LinkSelfContainedComponents::LINKER;
389+
// Any `+linker` or other component used is unstable, and that's an error.
390+
let unstable_enabled = self.enabled_components;
397391
let unstable_disabled = self.disabled_components - LinkSelfContainedComponents::LINKER;
398392
if !unstable_enabled.union(unstable_disabled).is_empty() {
399393
return Err(String::from(
400-
"only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`\
401-
/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use \
394+
"only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` \
395+
are stable, the `-Z unstable-options` flag must also be passed to use \
402396
the unstable values",
403397
));
404398
}

tests/run-make/rust-lld/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
rustc()
1515
.arg("-Clinker-features=+lld")
1616
.arg("-Clink-self-contained=+linker")
17-
.arg("-Zunstable-options") // needed for targets other than `x86_64-unknown-linux-gnu`
17+
.arg("-Zunstable-options") // the opt-ins are unstable
1818
.input("main.rs"),
1919
);
2020

tests/ui/linking/link-self-contained-linker-disallowed-target.positive.stderr

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/ui/linking/link-self-contained-linker-disallowed-target.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Check that only `-C link-self-contained=-linker` is stable on x64 linux. Any other value or
2+
// target, needs `-Z unstable-options`.
3+
4+
// ignore-tidy-linelength
5+
6+
//@ revisions: unstable_target_positive unstable_target_negative unstable_positive
7+
//@ [unstable_target_negative] compile-flags: --target=x86_64-unknown-linux-musl -C link-self-contained=-linker --crate-type=rlib
8+
//@ [unstable_target_negative] needs-llvm-components: x86
9+
//@ [unstable_target_positive] compile-flags: --target=x86_64-unknown-linux-musl -C link-self-contained=+linker --crate-type=rlib
10+
//@ [unstable_target_positive] needs-llvm-components: x86
11+
//@ [unstable_positive] compile-flags: --target=x86_64-unknown-linux-gnu -C link-self-contained=+linker --crate-type=rlib
12+
//@ [unstable_positive] needs-llvm-components: x86
13+
14+
#![feature(no_core)]
15+
#![no_core]
16+
17+
//[unstable_target_negative]~? ERROR `-C link-self-contained=-linker` is unstable on the `x86_64-unknown-linux-musl` target
18+
//[unstable_target_positive]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
19+
//[unstable_positive]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
2+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

tests/ui/linking/link-self-contained-unstable.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
fn main() {}
1212

13-
//[crto]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
14-
//[libc]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
15-
//[unwind]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
16-
//[sanitizers]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
17-
//[mingw]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
13+
//[crto]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
14+
//[libc]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
15+
//[unwind]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
16+
//[sanitizers]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
17+
//[mingw]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

0 commit comments

Comments
 (0)