@@ -283,22 +283,29 @@ impl OutputTypes {
283
283
// DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That
284
284
// would break dependency tracking for command-line arguments.
285
285
#[ derive( Clone , Hash ) ]
286
- pub struct Externs ( BTreeMap < String , BTreeSet < Option < String > > > ) ;
286
+ pub struct Externs ( BTreeMap < String , ExternEntry > ) ;
287
+
288
+ #[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug , Default ) ]
289
+ pub struct ExternEntry {
290
+ pub locations : BTreeSet < Option < String > > ,
291
+ pub is_private_dep : bool
292
+ }
287
293
288
294
impl Externs {
289
- pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
295
+ pub fn new ( data : BTreeMap < String , ExternEntry > ) -> Externs {
290
296
Externs ( data)
291
297
}
292
298
293
- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < Option < String > > > {
299
+ pub fn get ( & self , key : & str ) -> Option < & ExternEntry > {
294
300
self . 0 . get ( key)
295
301
}
296
302
297
- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < Option < String > > > {
303
+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , ExternEntry > {
298
304
self . 0 . iter ( )
299
305
}
300
306
}
301
307
308
+
302
309
macro_rules! hash_option {
303
310
( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ UNTRACKED ] ) => ( { } ) ;
304
311
( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ TRACKED ] ) => ( {
@@ -427,10 +434,6 @@ top_level_options!(
427
434
remap_path_prefix: Vec <( PathBuf , PathBuf ) > [ UNTRACKED ] ,
428
435
429
436
edition: Edition [ TRACKED ] ,
430
-
431
- // The list of crates to consider private when
432
- // checking leaked private dependency types in public interfaces
433
- extern_private: Vec <String > [ TRACKED ] ,
434
437
}
435
438
) ;
436
439
@@ -633,7 +636,6 @@ impl Default for Options {
633
636
cli_forced_thinlto_off : false ,
634
637
remap_path_prefix : Vec :: new ( ) ,
635
638
edition : DEFAULT_EDITION ,
636
- extern_private : Vec :: new ( )
637
639
}
638
640
}
639
641
}
@@ -2315,10 +2317,14 @@ pub fn build_session_options_and_crate_config(
2315
2317
)
2316
2318
}
2317
2319
2318
- let extern_private = matches. opt_strs ( "extern-private" ) ;
2320
+ // We start out with a Vec<(Option<String>, bool)>>,
2321
+ // and later convert it into a BTreeSet<(Option<String>, bool)>
2322
+ // This allows to modify entries in-place to set their correct
2323
+ // 'public' value
2324
+ let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
2325
+ for ( arg, private) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, false ) )
2326
+ . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, true ) ) ) {
2319
2327
2320
- let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2321
- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) . chain ( matches. opt_strs ( "extern-private" ) ) {
2322
2328
let mut parts = arg. splitn ( 2 , '=' ) ;
2323
2329
let name = parts. next ( ) . unwrap_or_else ( ||
2324
2330
early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2331,10 +2337,17 @@ pub fn build_session_options_and_crate_config(
2331
2337
) ;
2332
2338
} ;
2333
2339
2334
- externs
2340
+ let entry = externs
2335
2341
. entry ( name. to_owned ( ) )
2336
- . or_default ( )
2337
- . insert ( location) ;
2342
+ . or_default ( ) ;
2343
+
2344
+
2345
+ entry. locations . insert ( location. clone ( ) ) ;
2346
+
2347
+ // Crates start out being not private,
2348
+ // and go to being private if we see an '--extern-private'
2349
+ // flag
2350
+ entry. is_private_dep |= private;
2338
2351
}
2339
2352
2340
2353
let crate_name = matches. opt_str ( "crate-name" ) ;
@@ -2386,7 +2399,6 @@ pub fn build_session_options_and_crate_config(
2386
2399
cli_forced_thinlto_off : disable_thinlto,
2387
2400
remap_path_prefix,
2388
2401
edition,
2389
- extern_private
2390
2402
} ,
2391
2403
cfg,
2392
2404
)
@@ -2651,7 +2663,7 @@ mod tests {
2651
2663
build_session_options_and_crate_config,
2652
2664
to_crate_config
2653
2665
} ;
2654
- use crate :: session:: config:: { LtoCli , LinkerPluginLto , PgoGenerate } ;
2666
+ use crate :: session:: config:: { LtoCli , LinkerPluginLto , PgoGenerate , ExternEntry } ;
2655
2667
use crate :: session:: build_session;
2656
2668
use crate :: session:: search_paths:: SearchPath ;
2657
2669
use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -2664,6 +2676,19 @@ mod tests {
2664
2676
use syntax;
2665
2677
use super :: Options ;
2666
2678
2679
+ impl ExternEntry {
2680
+ fn new_public < S : Into < String > ,
2681
+ I : IntoIterator < Item = Option < S > > > ( locations : I ) -> ExternEntry {
2682
+ let locations: BTreeSet < _ > = locations. into_iter ( ) . map ( |o| o. map ( |s| s. into ( ) ) )
2683
+ . collect ( ) ;
2684
+
2685
+ ExternEntry {
2686
+ locations,
2687
+ is_private_dep : false
2688
+ }
2689
+ }
2690
+ }
2691
+
2667
2692
fn optgroups ( ) -> getopts:: Options {
2668
2693
let mut opts = getopts:: Options :: new ( ) ;
2669
2694
for group in super :: rustc_optgroups ( ) {
@@ -2676,10 +2701,6 @@ mod tests {
2676
2701
BTreeMap :: from_iter ( entries. into_iter ( ) )
2677
2702
}
2678
2703
2679
- fn mk_set < V : Ord > ( entries : Vec < V > ) -> BTreeSet < V > {
2680
- BTreeSet :: from_iter ( entries. into_iter ( ) )
2681
- }
2682
-
2683
2704
// When the user supplies --test we should implicitly supply --cfg test
2684
2705
#[ test]
2685
2706
fn test_switch_implies_cfg_test ( ) {
@@ -2797,33 +2818,33 @@ mod tests {
2797
2818
v1. externs = Externs :: new ( mk_map ( vec ! [
2798
2819
(
2799
2820
String :: from( "a" ) ,
2800
- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2821
+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
2801
2822
) ,
2802
2823
(
2803
2824
String :: from( "d" ) ,
2804
- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2825
+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
2805
2826
) ,
2806
2827
] ) ) ;
2807
2828
2808
2829
v2. externs = Externs :: new ( mk_map ( vec ! [
2809
2830
(
2810
2831
String :: from( "d" ) ,
2811
- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2832
+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
2812
2833
) ,
2813
2834
(
2814
2835
String :: from( "a" ) ,
2815
- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2836
+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
2816
2837
) ,
2817
2838
] ) ) ;
2818
2839
2819
2840
v3. externs = Externs :: new ( mk_map ( vec ! [
2820
2841
(
2821
2842
String :: from( "a" ) ,
2822
- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2843
+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
2823
2844
) ,
2824
2845
(
2825
2846
String :: from( "d" ) ,
2826
- mk_set ( vec![ Some ( String :: from ( "f" ) ) , Some ( String :: from ( "e" ) ) ] ) ,
2847
+ ExternEntry :: new_public ( vec![ Some ( "f" ) , Some ( "e" ) ] )
2827
2848
) ,
2828
2849
] ) ) ;
2829
2850
0 commit comments