@@ -11,7 +11,7 @@ use crate::{EarlyErrorHandler, Session};
1111use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1212use rustc_data_structures:: stable_hasher:: { StableOrd , ToStableHashKey } ;
1313use rustc_target:: abi:: Align ;
14- use rustc_target:: spec:: { LinkerFlavorCli , PanicStrategy , SanitizerSet , SplitDebuginfo } ;
14+ use rustc_target:: spec:: { PanicStrategy , SanitizerSet , SplitDebuginfo } ;
1515use rustc_target:: spec:: { Target , TargetTriple , TargetWarnings , TARGETS } ;
1616
1717use crate :: parse:: { CrateCheckConfig , CrateConfig } ;
@@ -308,6 +308,14 @@ impl LinkSelfContained {
308308 on
309309 }
310310
311+ /// To help checking CLI usage while some of the values are unstable: returns whether one of the
312+ /// components was set individually. This would also require the `-Zunstable-options` flag, to
313+ /// be allowed.
314+ fn are_unstable_variants_set ( & self ) -> bool {
315+ let any_component_set = !self . components . is_empty ( ) ;
316+ self . explicitly_set . is_none ( ) && any_component_set
317+ }
318+
311319 /// Returns whether the self-contained linker component is enabled.
312320 pub fn linker ( & self ) -> bool {
313321 self . components . contains ( LinkSelfContainedComponents :: LINKER )
@@ -2648,16 +2656,28 @@ pub fn build_session_options(
26482656 }
26492657 }
26502658
2651- if let Some ( flavor) = cg. linker_flavor {
2652- if matches ! ( flavor, LinkerFlavorCli :: BpfLinker | LinkerFlavorCli :: PtxLinker )
2653- && !nightly_options:: is_unstable_enabled ( matches)
2654- {
2655- let msg = format ! (
2656- "linker flavor `{}` is unstable, `-Z unstable-options` \
2657- flag must also be passed to explicitly use it",
2658- flavor. desc( )
2659+ // For testing purposes, until we have more feedback about these options: ensure `-Z
2660+ // unstable-options` is required when using the unstable `-C link-self-contained` options, like
2661+ // `-C link-self-contained=+linker`, and when using the unstable `-C linker-flavor` options, like
2662+ // `-C linker-flavor=gnu-lld-cc`.
2663+ if !nightly_options:: is_unstable_enabled ( matches) {
2664+ let uses_unstable_self_contained_option =
2665+ cg. link_self_contained . are_unstable_variants_set ( ) ;
2666+ if uses_unstable_self_contained_option {
2667+ handler. early_error (
2668+ "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off` are stable, \
2669+ the `-Z unstable-options` flag must also be passed to use the unstable values",
26592670 ) ;
2660- handler. early_error ( msg) ;
2671+ }
2672+
2673+ if let Some ( flavor) = cg. linker_flavor {
2674+ if flavor. is_unstable ( ) {
2675+ handler. early_error ( format ! (
2676+ "the linker flavor `{}` is unstable, the `-Z unstable-options` \
2677+ flag must also be passed to use the unstable values",
2678+ flavor. desc( )
2679+ ) ) ;
2680+ }
26612681 }
26622682 }
26632683
0 commit comments