@@ -268,33 +268,24 @@ 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 , BTreeSet < ExternEntry > > ) ;
272
272
273
+ #[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug ) ]
274
+ pub struct ExternEntry {
275
+ pub location : Option < String > ,
276
+ pub public : bool
277
+ }
273
278
274
279
impl Externs {
275
- pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
280
+ pub fn new ( data : BTreeMap < String , BTreeSet < ExternEntry > > ) -> Externs {
276
281
Externs ( data)
277
282
}
278
283
279
- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < Option < String > > > {
280
- self . 0 . get ( key)
281
- }
282
-
283
- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < Option < String > > > {
284
- self . 0 . iter ( )
285
- }
286
- }
287
-
288
- // Similar to 'Externs', but used for the '--extern-private' option
289
- #[ derive( Clone , Hash ) ]
290
- pub struct ExternPrivates ( BTreeMap < String , BTreeSet < String > > ) ;
291
-
292
- impl ExternPrivates {
293
- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < String > > {
284
+ pub fn get ( & self , key : & str ) -> Option < & BTreeSet < ExternEntry > > {
294
285
self . 0 . get ( key)
295
286
}
296
287
297
- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < String > > {
288
+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < ExternEntry > > {
298
289
self . 0 . iter ( )
299
290
}
300
291
}
@@ -431,7 +422,7 @@ top_level_options!(
431
422
432
423
// The crates to consider private when
433
424
// checking leaked private dependency types in public interfaces
434
- extern_private: ExternPrivates [ UNTRACKED ] ,
425
+ // extern_private: ExternPrivates [UNTRACKED],
435
426
}
436
427
) ;
437
428
@@ -634,7 +625,7 @@ impl Default for Options {
634
625
cli_forced_thinlto_off : false ,
635
626
remap_path_prefix : Vec :: new ( ) ,
636
627
edition : DEFAULT_EDITION ,
637
- extern_private : ExternPrivates ( BTreeMap :: new ( ) )
628
+ // extern_private: ExternPrivates(BTreeMap::new())
638
629
}
639
630
}
640
631
}
@@ -2304,7 +2295,7 @@ pub fn build_session_options_and_crate_config(
2304
2295
)
2305
2296
}
2306
2297
2307
- let mut extern_private: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2298
+ /* let mut extern_private: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
2308
2299
2309
2300
for arg in matches.opt_strs("extern-private").into_iter() {
2310
2301
let mut parts = arg.splitn(2, '=');
@@ -2319,10 +2310,16 @@ pub fn build_session_options_and_crate_config(
2319
2310
.or_default()
2320
2311
.insert(location);
2321
2312
2322
- }
2313
+ }*/
2314
+
2315
+ // We start out with a Vec<(Option<String>, bool)>>,
2316
+ // and later convert it into a BTreeSet<(Option<String>, bool)>
2317
+ // This allows to modify entries in-place to set their correct
2318
+ // 'public' value
2319
+ let mut externs: BTreeMap < _ , BTreeMap < Option < String > , bool > > = BTreeMap :: new ( ) ;
2320
+ for ( arg, public) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, true ) )
2321
+ . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, false ) ) ) {
2323
2322
2324
- let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2325
- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) {
2326
2323
let mut parts = arg. splitn ( 2 , '=' ) ;
2327
2324
let name = parts. next ( ) . unwrap_or_else ( ||
2328
2325
early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2335,11 +2332,37 @@ pub fn build_session_options_and_crate_config(
2335
2332
) ;
2336
2333
} ;
2337
2334
2335
+
2336
+ // Externsl crates start out public,
2337
+ // and become private if we later see
2338
+ // an '--extern-private' key. They never
2339
+ // go back to being public once we've seen
2340
+ // '--extern-private', so we logical-AND
2341
+ // their current and new 'public' value together
2342
+
2338
2343
externs
2339
2344
. entry ( name. to_owned ( ) )
2340
2345
. or_default ( )
2341
- . insert ( location) ;
2342
- }
2346
+ . entry ( location)
2347
+ . and_modify ( |e| * e &= public)
2348
+ . or_insert ( public) ;
2349
+ }
2350
+
2351
+ // Now that we've determined the 'public' status of each extern,
2352
+ // collect them into a set of ExternEntry
2353
+ let externs: BTreeMap < String , BTreeSet < ExternEntry > > = externs. into_iter ( )
2354
+ . map ( |( k, v) | {
2355
+ let values =v. into_iter ( ) . map ( |( location, public) | {
2356
+ ExternEntry {
2357
+ location,
2358
+ public
2359
+ }
2360
+ } ) . collect :: < BTreeSet < ExternEntry > > ( ) ;
2361
+ ( k, values)
2362
+ } )
2363
+ . collect ( ) ;
2364
+
2365
+
2343
2366
2344
2367
let crate_name = matches. opt_str ( "crate-name" ) ;
2345
2368
@@ -2390,7 +2413,7 @@ pub fn build_session_options_and_crate_config(
2390
2413
cli_forced_thinlto_off : disable_thinlto,
2391
2414
remap_path_prefix,
2392
2415
edition,
2393
- extern_private : ExternPrivates ( extern_private)
2416
+ // extern_private: ExternPrivates(extern_private)
2394
2417
} ,
2395
2418
cfg,
2396
2419
)
0 commit comments