@@ -270,6 +270,7 @@ impl OutputTypes {
270270#[ derive( Clone , Hash ) ]
271271pub struct Externs ( BTreeMap < String , BTreeSet < Option < String > > > ) ;
272272
273+
273274impl Externs {
274275 pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
275276 Externs ( data)
@@ -284,6 +285,21 @@ impl Externs {
284285 }
285286}
286287
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 > > {
294+ self . 0 . get ( key)
295+ }
296+
297+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < String > > {
298+ self . 0 . iter ( )
299+ }
300+ }
301+
302+
287303macro_rules! hash_option {
288304 ( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ UNTRACKED ] ) => ( { } ) ;
289305 ( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ TRACKED ] ) => ( {
@@ -413,9 +429,9 @@ top_level_options!(
413429
414430 edition: Edition [ TRACKED ] ,
415431
416- // The list of crates to consider private when
432+ // The crates to consider private when
417433 // checking leaked private dependency types in public interfaces
418- extern_private: Vec < String > [ TRACKED ] ,
434+ extern_private: ExternPrivates [ UNTRACKED ] ,
419435 }
420436) ;
421437
@@ -618,7 +634,7 @@ impl Default for Options {
618634 cli_forced_thinlto_off : false ,
619635 remap_path_prefix : Vec :: new ( ) ,
620636 edition : DEFAULT_EDITION ,
621- extern_private : Vec :: new ( )
637+ extern_private : ExternPrivates ( BTreeMap :: new ( ) )
622638 }
623639 }
624640}
@@ -2288,10 +2304,25 @@ pub fn build_session_options_and_crate_config(
22882304 )
22892305 }
22902306
2291- let extern_private = matches. opt_strs ( "extern-private" ) ;
2307+ let mut extern_private: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2308+
2309+ for arg in matches. opt_strs ( "extern-private" ) . into_iter ( ) {
2310+ let mut parts = arg. splitn ( 2 , '=' ) ;
2311+ let name = parts. next ( ) . unwrap_or_else ( ||
2312+ early_error ( error_format, "--extern-private value must not be empty" ) ) ;
2313+ let location = parts. next ( ) . map ( |s| s. to_string ( ) ) . unwrap_or_else ( ||
2314+ early_error ( error_format, "--extern-private value must include a location" ) ) ;
2315+
2316+
2317+ extern_private
2318+ . entry ( name. to_owned ( ) )
2319+ . or_default ( )
2320+ . insert ( location) ;
2321+
2322+ }
22922323
22932324 let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2294- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) . chain ( matches . opt_strs ( "extern-private" ) ) {
2325+ for arg in matches. opt_strs ( "extern" ) . into_iter ( ) {
22952326 let mut parts = arg. splitn ( 2 , '=' ) ;
22962327 let name = parts. next ( ) . unwrap_or_else ( ||
22972328 early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2359,7 +2390,7 @@ pub fn build_session_options_and_crate_config(
23592390 cli_forced_thinlto_off : disable_thinlto,
23602391 remap_path_prefix,
23612392 edition,
2362- extern_private
2393+ extern_private : ExternPrivates ( extern_private )
23632394 } ,
23642395 cfg,
23652396 )
0 commit comments