@@ -268,22 +268,29 @@ impl OutputTypes {
268268// DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That
269269// would break dependency tracking for command-line arguments.
270270#[ 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+ }
272278
273279impl Externs {
274- pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
280+ pub fn new ( data : BTreeMap < String , ExternEntry > ) -> Externs {
275281 Externs ( data)
276282 }
277283
278- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < Option < String > > > {
284+ pub fn get ( & self , key : & str ) -> Option < & ExternEntry > {
279285 self . 0 . get ( key)
280286 }
281287
282- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < Option < String > > > {
288+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , ExternEntry > {
283289 self . 0 . iter ( )
284290 }
285291}
286292
293+
287294macro_rules! hash_option {
288295 ( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ UNTRACKED ] ) => ( { } ) ;
289296 ( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ TRACKED ] ) => ( {
@@ -412,10 +419,6 @@ top_level_options!(
412419 remap_path_prefix: Vec <( PathBuf , PathBuf ) > [ UNTRACKED ] ,
413420
414421 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 ] ,
419422 }
420423) ;
421424
@@ -618,7 +621,6 @@ impl Default for Options {
618621 cli_forced_thinlto_off : false ,
619622 remap_path_prefix : Vec :: new ( ) ,
620623 edition : DEFAULT_EDITION ,
621- extern_private : Vec :: new ( )
622624 }
623625 }
624626}
@@ -2290,10 +2292,14 @@ pub fn build_session_options_and_crate_config(
22902292 )
22912293 }
22922294
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 ) ) ) {
22942302
2295- let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2296- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) . chain ( matches. opt_strs ( "extern-private" ) ) {
22972303 let mut parts = arg. splitn ( 2 , '=' ) ;
22982304 let name = parts. next ( ) . unwrap_or_else ( ||
22992305 early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2306,10 +2312,17 @@ pub fn build_session_options_and_crate_config(
23062312 ) ;
23072313 } ;
23082314
2309- externs
2315+ let entry = externs
23102316 . 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;
23132326 }
23142327
23152328 let crate_name = matches. opt_str ( "crate-name" ) ;
@@ -2361,7 +2374,6 @@ pub fn build_session_options_and_crate_config(
23612374 cli_forced_thinlto_off : disable_thinlto,
23622375 remap_path_prefix,
23632376 edition,
2364- extern_private
23652377 } ,
23662378 cfg,
23672379 )
@@ -2625,7 +2637,7 @@ mod tests {
26252637 build_session_options_and_crate_config,
26262638 to_crate_config
26272639 } ;
2628- use crate :: session:: config:: { LtoCli , LinkerPluginLto } ;
2640+ use crate :: session:: config:: { LtoCli , LinkerPluginLto , ExternEntry } ;
26292641 use crate :: session:: build_session;
26302642 use crate :: session:: search_paths:: SearchPath ;
26312643 use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -2638,6 +2650,19 @@ mod tests {
26382650 use syntax;
26392651 use super :: Options ;
26402652
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+
26412666 fn optgroups ( ) -> getopts:: Options {
26422667 let mut opts = getopts:: Options :: new ( ) ;
26432668 for group in super :: rustc_optgroups ( ) {
@@ -2650,10 +2675,6 @@ mod tests {
26502675 BTreeMap :: from_iter ( entries. into_iter ( ) )
26512676 }
26522677
2653- fn mk_set < V : Ord > ( entries : Vec < V > ) -> BTreeSet < V > {
2654- BTreeSet :: from_iter ( entries. into_iter ( ) )
2655- }
2656-
26572678 // When the user supplies --test we should implicitly supply --cfg test
26582679 #[ test]
26592680 fn test_switch_implies_cfg_test ( ) {
@@ -2771,33 +2792,33 @@ mod tests {
27712792 v1. externs = Externs :: new ( mk_map ( vec ! [
27722793 (
27732794 String :: from( "a" ) ,
2774- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2795+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
27752796 ) ,
27762797 (
27772798 String :: from( "d" ) ,
2778- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2799+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
27792800 ) ,
27802801 ] ) ) ;
27812802
27822803 v2. externs = Externs :: new ( mk_map ( vec ! [
27832804 (
27842805 String :: from( "d" ) ,
2785- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2806+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
27862807 ) ,
27872808 (
27882809 String :: from( "a" ) ,
2789- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2810+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
27902811 ) ,
27912812 ] ) ) ;
27922813
27932814 v3. externs = Externs :: new ( mk_map ( vec ! [
27942815 (
27952816 String :: from( "a" ) ,
2796- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2817+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
27972818 ) ,
27982819 (
27992820 String :: from( "d" ) ,
2800- mk_set ( vec![ Some ( String :: from ( "f" ) ) , Some ( String :: from ( "e" ) ) ] ) ,
2821+ ExternEntry :: new_public ( vec![ Some ( "f" ) , Some ( "e" ) ] )
28012822 ) ,
28022823 ] ) ) ;
28032824
0 commit comments