Skip to content

Commit 5d77479

Browse files
committed
Guard new variants of -C prefer-dynamic=... via -Z flags.
1 parent bf817f6 commit 5d77479

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,36 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
21682168
}
21692169
}
21702170

2171+
if !debugging_opts.unstable_options {
2172+
// if the user hasn't specified `-Z unstable-options`, then they need to have opted into
2173+
// certain unstable variants of `-C prefer-dynamic` explicitly
2174+
if let PreferDynamicSet::Set(s) = &cg.prefer_dynamic {
2175+
if s.len() == 1 && s.iter().next().map(|s| s.as_str()) == Some("std") {
2176+
// as a special case, `-C prefer-dynamic=std` gets its own `-Z` flag (because it is
2177+
// on a shorter-term stabilization path).
2178+
if debugging_opts.prefer_dynamic_std {
2179+
// okay, user opted-into `-C prefer-dynamic=std` via `-Z prefer-dynamic-std`
2180+
} else if debugging_opts.prefer_dynamic_subset {
2181+
// okay, user opted-into arbitrary `-C prefer-dynamic=...` via `-Z prefer-dynamic-subset`
2182+
} else {
2183+
early_error(
2184+
error_format,
2185+
"`-C prefer-dynamic=std` is unstable: set `-Z prefer-dynamic-std`",
2186+
);
2187+
}
2188+
} else {
2189+
if debugging_opts.prefer_dynamic_subset {
2190+
// okay, user opted-into arbitrary `-C prefer-dynamic=...` via `-Z prefer-dynamic-subset`
2191+
} else {
2192+
early_error(
2193+
error_format,
2194+
"`-C prefer-dynamic=crate,...` is unstable: set `-Z prefer-dynamic-subset`",
2195+
);
2196+
}
2197+
}
2198+
}
2199+
}
2200+
21712201
// Try to find a directory containing the Rust `src`, for more details see
21722202
// the doc comment on the `real_rust_source_base_dir` field.
21732203
let tmp_buf;

compiler/rustc_session/src/options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@ options! {
12381238
"use a more precise version of drop elaboration for matches on enums (default: yes). \
12391239
This results in better codegen, but has caused miscompilations on some tier 2 platforms. \
12401240
See #77382 and #74551."),
1241+
prefer_dynamic_std: bool = (false, parse_bool, [UNTRACKED],
1242+
"enable use of unstable `-C prefer-dynamic=std` variant"),
1243+
prefer_dynamic_subset: bool = (false, parse_bool, [UNTRACKED],
1244+
"enable use of unstable `-C prefer-dynamic=crate1,crate2,...` variant"),
12411245
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
12421246
"make rustc print the total optimization fuel used by a crate"),
12431247
print_link_args: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)