@@ -268,22 +268,29 @@ impl OutputTypes {
268
268
// DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That
269
269
// would break dependency tracking for command-line arguments.
270
270
#[ derive( Clone , Hash ) ]
271
- pub struct Externs ( BTreeMap < String , BTreeSet < Option < String > > > ) ;
271
+ pub struct Externs ( BTreeMap < String , ExternEntry > ) ;
272
+
273
+ #[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug , Default ) ]
274
+ pub struct ExternEntry {
275
+ pub locations : BTreeSet < Option < String > > ,
276
+ pub is_private_dep : bool
277
+ }
272
278
273
279
impl Externs {
274
- pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
280
+ pub fn new ( data : BTreeMap < String , ExternEntry > ) -> Externs {
275
281
Externs ( data)
276
282
}
277
283
278
- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < Option < String > > > {
284
+ pub fn get ( & self , key : & str ) -> Option < & ExternEntry > {
279
285
self . 0 . get ( key)
280
286
}
281
287
282
- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < Option < String > > > {
288
+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , ExternEntry > {
283
289
self . 0 . iter ( )
284
290
}
285
291
}
286
292
293
+
287
294
macro_rules! hash_option {
288
295
( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ UNTRACKED ] ) => ( { } ) ;
289
296
( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ TRACKED ] ) => ( {
@@ -412,10 +419,6 @@ top_level_options!(
412
419
remap_path_prefix: Vec <( PathBuf , PathBuf ) > [ UNTRACKED ] ,
413
420
414
421
edition: Edition [ TRACKED ] ,
415
-
416
- // The list of crates to consider private when
417
- // checking leaked private dependency types in public interfaces
418
- extern_private: Vec <String > [ TRACKED ] ,
419
422
}
420
423
) ;
421
424
@@ -618,7 +621,6 @@ impl Default for Options {
618
621
cli_forced_thinlto_off : false ,
619
622
remap_path_prefix : Vec :: new ( ) ,
620
623
edition : DEFAULT_EDITION ,
621
- extern_private : Vec :: new ( )
622
624
}
623
625
}
624
626
}
@@ -2290,10 +2292,14 @@ pub fn build_session_options_and_crate_config(
2290
2292
)
2291
2293
}
2292
2294
2293
- let extern_private = matches. opt_strs ( "extern-private" ) ;
2295
+ // We start out with a Vec<(Option<String>, bool)>>,
2296
+ // and later convert it into a BTreeSet<(Option<String>, bool)>
2297
+ // This allows to modify entries in-place to set their correct
2298
+ // 'public' value
2299
+ let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
2300
+ for ( arg, private) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, false ) )
2301
+ . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, true ) ) ) {
2294
2302
2295
- let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2296
- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) . chain ( matches. opt_strs ( "extern-private" ) ) {
2297
2303
let mut parts = arg. splitn ( 2 , '=' ) ;
2298
2304
let name = parts. next ( ) . unwrap_or_else ( ||
2299
2305
early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2306,10 +2312,17 @@ pub fn build_session_options_and_crate_config(
2306
2312
) ;
2307
2313
} ;
2308
2314
2309
- externs
2315
+ let entry = externs
2310
2316
. entry ( name. to_owned ( ) )
2311
- . or_default ( )
2312
- . insert ( location) ;
2317
+ . or_default ( ) ;
2318
+
2319
+
2320
+ entry. locations . insert ( location. clone ( ) ) ;
2321
+
2322
+ // Crates start out being not private,
2323
+ // and go to being private if we see an '--extern-private'
2324
+ // flag
2325
+ entry. is_private_dep |= private;
2313
2326
}
2314
2327
2315
2328
let crate_name = matches. opt_str ( "crate-name" ) ;
@@ -2361,7 +2374,6 @@ pub fn build_session_options_and_crate_config(
2361
2374
cli_forced_thinlto_off : disable_thinlto,
2362
2375
remap_path_prefix,
2363
2376
edition,
2364
- extern_private
2365
2377
} ,
2366
2378
cfg,
2367
2379
)
@@ -2625,7 +2637,7 @@ mod tests {
2625
2637
build_session_options_and_crate_config,
2626
2638
to_crate_config
2627
2639
} ;
2628
- use crate :: session:: config:: { LtoCli , LinkerPluginLto } ;
2640
+ use crate :: session:: config:: { LtoCli , LinkerPluginLto , ExternEntry } ;
2629
2641
use crate :: session:: build_session;
2630
2642
use crate :: session:: search_paths:: SearchPath ;
2631
2643
use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -2638,6 +2650,19 @@ mod tests {
2638
2650
use syntax;
2639
2651
use super :: Options ;
2640
2652
2653
+ impl ExternEntry {
2654
+ fn new_public < S : Into < String > ,
2655
+ I : IntoIterator < Item = Option < S > > > ( locations : I ) -> ExternEntry {
2656
+ let locations: BTreeSet < _ > = locations. into_iter ( ) . map ( |o| o. map ( |s| s. into ( ) ) )
2657
+ . collect ( ) ;
2658
+
2659
+ ExternEntry {
2660
+ locations,
2661
+ is_private_dep : false
2662
+ }
2663
+ }
2664
+ }
2665
+
2641
2666
fn optgroups ( ) -> getopts:: Options {
2642
2667
let mut opts = getopts:: Options :: new ( ) ;
2643
2668
for group in super :: rustc_optgroups ( ) {
@@ -2650,10 +2675,6 @@ mod tests {
2650
2675
BTreeMap :: from_iter ( entries. into_iter ( ) )
2651
2676
}
2652
2677
2653
- fn mk_set < V : Ord > ( entries : Vec < V > ) -> BTreeSet < V > {
2654
- BTreeSet :: from_iter ( entries. into_iter ( ) )
2655
- }
2656
-
2657
2678
// When the user supplies --test we should implicitly supply --cfg test
2658
2679
#[ test]
2659
2680
fn test_switch_implies_cfg_test ( ) {
@@ -2771,33 +2792,33 @@ mod tests {
2771
2792
v1. externs = Externs :: new ( mk_map ( vec ! [
2772
2793
(
2773
2794
String :: from( "a" ) ,
2774
- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2795
+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
2775
2796
) ,
2776
2797
(
2777
2798
String :: from( "d" ) ,
2778
- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2799
+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
2779
2800
) ,
2780
2801
] ) ) ;
2781
2802
2782
2803
v2. externs = Externs :: new ( mk_map ( vec ! [
2783
2804
(
2784
2805
String :: from( "d" ) ,
2785
- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2806
+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
2786
2807
) ,
2787
2808
(
2788
2809
String :: from( "a" ) ,
2789
- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2810
+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
2790
2811
) ,
2791
2812
] ) ) ;
2792
2813
2793
2814
v3. externs = Externs :: new ( mk_map ( vec ! [
2794
2815
(
2795
2816
String :: from( "a" ) ,
2796
- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2817
+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
2797
2818
) ,
2798
2819
(
2799
2820
String :: from( "d" ) ,
2800
- mk_set ( vec![ Some ( String :: from ( "f" ) ) , Some ( String :: from ( "e" ) ) ] ) ,
2821
+ ExternEntry :: new_public ( vec![ Some ( "f" ) , Some ( "e" ) ] )
2801
2822
) ,
2802
2823
] ) ) ;
2803
2824
0 commit comments