File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,17 @@ impl LinkSelfContained {
306306 pub fn is_linker_disabled ( & self ) -> bool {
307307 self . disabled_components . contains ( LinkSelfContainedComponents :: LINKER )
308308 }
309+
310+ /// Returns CLI inconsistencies to emit errors: individual components were both enabled and
311+ /// disabled.
312+ fn check_consistency ( & self ) -> Option < LinkSelfContainedComponents > {
313+ if self . explicitly_set . is_some ( ) {
314+ None
315+ } else {
316+ let common = self . enabled_components . intersection ( self . disabled_components ) ;
317+ if common. is_empty ( ) { None } else { Some ( common) }
318+ }
319+ }
309320}
310321
311322/// Used with `-Z assert-incr-state`.
@@ -2766,6 +2777,19 @@ pub fn build_session_options(
27662777 }
27672778 }
27682779
2780+ // Check `-C link-self-contained` for consistency: individual components cannot be both enabled
2781+ // and disabled at the same time.
2782+ if let Some ( erroneous_components) = cg. link_self_contained . check_consistency ( ) {
2783+ let names: String = erroneous_components
2784+ . into_iter ( )
2785+ . map ( |c| c. as_str ( ) . unwrap ( ) )
2786+ . intersperse ( ", " )
2787+ . collect ( ) ;
2788+ handler. early_error ( format ! (
2789+ "some `-C link-self-contained` components were both enabled and disabled: {names}"
2790+ ) ) ;
2791+ }
2792+
27692793 let prints = collect_print_requests ( handler, & mut cg, & mut unstable_opts, matches) ;
27702794
27712795 let cg = cg;
Original file line number Diff line number Diff line change 66#![ feature( option_get_or_insert_default) ]
77#![ feature( rustc_attrs) ]
88#![ feature( map_many_mut) ]
9+ #![ feature( iter_intersperse) ]
910#![ recursion_limit = "256" ]
1011#![ allow( rustc:: potential_query_instability) ]
1112#![ deny( rustc:: untranslatable_diagnostic) ]
Original file line number Diff line number Diff line change @@ -670,7 +670,7 @@ impl LinkSelfContainedComponents {
670670 /// Return the component's name.
671671 ///
672672 /// Returns `None` if the bitflags aren't a singular component (but a mix of multiple flags).
673- fn as_str ( self ) -> Option < & ' static str > {
673+ pub fn as_str ( self ) -> Option < & ' static str > {
674674 Some ( match self {
675675 LinkSelfContainedComponents :: CRT_OBJECTS => "crto" ,
676676 LinkSelfContainedComponents :: LIBC => "libc" ,
You can’t perform that action at this time.
0 commit comments