@@ -283,33 +283,24 @@ 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 , BTreeSet < ExternEntry > > ) ;
287
287
288
+ #[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug ) ]
289
+ pub struct ExternEntry {
290
+ pub location : Option < String > ,
291
+ pub public : bool
292
+ }
288
293
289
294
impl Externs {
290
- pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
295
+ pub fn new ( data : BTreeMap < String , BTreeSet < ExternEntry > > ) -> Externs {
291
296
Externs ( data)
292
297
}
293
298
294
- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < Option < String > > > {
295
- self . 0 . get ( key)
296
- }
297
-
298
- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < Option < String > > > {
299
- self . 0 . iter ( )
300
- }
301
- }
302
-
303
- // Similar to 'Externs', but used for the '--extern-private' option
304
- #[ derive( Clone , Hash ) ]
305
- pub struct ExternPrivates ( BTreeMap < String , BTreeSet < String > > ) ;
306
-
307
- impl ExternPrivates {
308
- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < String > > {
299
+ pub fn get ( & self , key : & str ) -> Option < & BTreeSet < ExternEntry > > {
309
300
self . 0 . get ( key)
310
301
}
311
302
312
- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < String > > {
303
+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < ExternEntry > > {
313
304
self . 0 . iter ( )
314
305
}
315
306
}
@@ -446,7 +437,7 @@ top_level_options!(
446
437
447
438
// The crates to consider private when
448
439
// checking leaked private dependency types in public interfaces
449
- extern_private: ExternPrivates [ UNTRACKED ] ,
440
+ // extern_private: ExternPrivates [UNTRACKED],
450
441
}
451
442
) ;
452
443
@@ -649,7 +640,7 @@ impl Default for Options {
649
640
cli_forced_thinlto_off : false ,
650
641
remap_path_prefix : Vec :: new ( ) ,
651
642
edition : DEFAULT_EDITION ,
652
- extern_private : ExternPrivates ( BTreeMap :: new ( ) )
643
+ // extern_private: ExternPrivates(BTreeMap::new())
653
644
}
654
645
}
655
646
}
@@ -2331,7 +2322,7 @@ pub fn build_session_options_and_crate_config(
2331
2322
)
2332
2323
}
2333
2324
2334
- let mut extern_private: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2325
+ /* let mut extern_private: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
2335
2326
2336
2327
for arg in matches.opt_strs("extern-private").into_iter() {
2337
2328
let mut parts = arg.splitn(2, '=');
@@ -2346,10 +2337,16 @@ pub fn build_session_options_and_crate_config(
2346
2337
.or_default()
2347
2338
.insert(location);
2348
2339
2349
- }
2340
+ }*/
2341
+
2342
+ // We start out with a Vec<(Option<String>, bool)>>,
2343
+ // and later convert it into a BTreeSet<(Option<String>, bool)>
2344
+ // This allows to modify entries in-place to set their correct
2345
+ // 'public' value
2346
+ let mut externs: BTreeMap < _ , BTreeMap < Option < String > , bool > > = BTreeMap :: new ( ) ;
2347
+ for ( arg, public) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, true ) )
2348
+ . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, false ) ) ) {
2350
2349
2351
- let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2352
- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) {
2353
2350
let mut parts = arg. splitn ( 2 , '=' ) ;
2354
2351
let name = parts. next ( ) . unwrap_or_else ( ||
2355
2352
early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2362,11 +2359,37 @@ pub fn build_session_options_and_crate_config(
2362
2359
) ;
2363
2360
} ;
2364
2361
2362
+
2363
+ // Externsl crates start out public,
2364
+ // and become private if we later see
2365
+ // an '--extern-private' key. They never
2366
+ // go back to being public once we've seen
2367
+ // '--extern-private', so we logical-AND
2368
+ // their current and new 'public' value together
2369
+
2365
2370
externs
2366
2371
. entry ( name. to_owned ( ) )
2367
2372
. or_default ( )
2368
- . insert ( location) ;
2369
- }
2373
+ . entry ( location)
2374
+ . and_modify ( |e| * e &= public)
2375
+ . or_insert ( public) ;
2376
+ }
2377
+
2378
+ // Now that we've determined the 'public' status of each extern,
2379
+ // collect them into a set of ExternEntry
2380
+ let externs: BTreeMap < String , BTreeSet < ExternEntry > > = externs. into_iter ( )
2381
+ . map ( |( k, v) | {
2382
+ let values =v. into_iter ( ) . map ( |( location, public) | {
2383
+ ExternEntry {
2384
+ location,
2385
+ public
2386
+ }
2387
+ } ) . collect :: < BTreeSet < ExternEntry > > ( ) ;
2388
+ ( k, values)
2389
+ } )
2390
+ . collect ( ) ;
2391
+
2392
+
2370
2393
2371
2394
let crate_name = matches. opt_str ( "crate-name" ) ;
2372
2395
@@ -2417,7 +2440,7 @@ pub fn build_session_options_and_crate_config(
2417
2440
cli_forced_thinlto_off : disable_thinlto,
2418
2441
remap_path_prefix,
2419
2442
edition,
2420
- extern_private : ExternPrivates ( extern_private)
2443
+ // extern_private: ExternPrivates(extern_private)
2421
2444
} ,
2422
2445
cfg,
2423
2446
)
0 commit comments