@@ -11,7 +11,7 @@ use crate::{EarlyErrorHandler, Session};
11
11
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
12
12
use rustc_data_structures:: stable_hasher:: { StableOrd , ToStableHashKey } ;
13
13
use rustc_target:: abi:: Align ;
14
- use rustc_target:: spec:: { LinkerFlavorCli , PanicStrategy , SanitizerSet , SplitDebuginfo } ;
14
+ use rustc_target:: spec:: { PanicStrategy , SanitizerSet , SplitDebuginfo } ;
15
15
use rustc_target:: spec:: { Target , TargetTriple , TargetWarnings , TARGETS } ;
16
16
17
17
use crate :: parse:: { CrateCheckConfig , CrateConfig } ;
@@ -308,6 +308,14 @@ impl LinkSelfContained {
308
308
on
309
309
}
310
310
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
+
311
319
/// Returns whether the self-contained linker component is enabled.
312
320
pub fn linker ( & self ) -> bool {
313
321
self . components . contains ( LinkSelfContainedComponents :: LINKER )
@@ -2648,16 +2656,28 @@ pub fn build_session_options(
2648
2656
}
2649
2657
}
2650
2658
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",
2659
2670
) ;
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
+ }
2661
2681
}
2662
2682
}
2663
2683
0 commit comments