@@ -283,26 +283,24 @@ impl OutputTypes {
283283// DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That
284284// would break dependency tracking for command-line arguments.
285285#[ derive( Clone , Hash ) ]
286- pub struct Externs ( BTreeMap < String , BTreeSet < ExternEntry > > ) ;
286+ pub struct Externs ( BTreeMap < String , ExternEntry > ) ;
287287
288288#[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug ) ]
289289pub struct ExternEntry {
290- pub location : Option < String > ,
291- pub public : bool
290+ pub locations : BTreeSet < Option < String > > ,
291+ pub is_private_dep : bool
292292}
293293
294-
295-
296294impl Externs {
297- pub fn new ( data : BTreeMap < String , BTreeSet < ExternEntry > > ) -> Externs {
295+ pub fn new ( data : BTreeMap < String , ExternEntry > ) -> Externs {
298296 Externs ( data)
299297 }
300298
301- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < ExternEntry > > {
299+ pub fn get ( & self , key : & str ) -> Option < & ExternEntry > {
302300 self . 0 . get ( key)
303301 }
304302
305- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < ExternEntry > > {
303+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , ExternEntry > {
306304 self . 0 . iter ( )
307305 }
308306}
@@ -2323,9 +2321,9 @@ pub fn build_session_options_and_crate_config(
23232321 // and later convert it into a BTreeSet<(Option<String>, bool)>
23242322 // This allows to modify entries in-place to set their correct
23252323 // 'public' value
2326- let mut externs: BTreeMap < _ , BTreeMap < Option < String > , bool > > = BTreeMap :: new ( ) ;
2327- for ( arg, public ) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, true ) )
2328- . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, false ) ) ) {
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 ) ) ) {
23292327
23302328 let mut parts = arg. splitn ( 2 , '=' ) ;
23312329 let name = parts. next ( ) . unwrap_or_else ( ||
@@ -2340,36 +2338,26 @@ pub fn build_session_options_and_crate_config(
23402338 } ;
23412339
23422340
2343- // Extern crates start out public,
2344- // and become private if we later see
2345- // an '--extern-private' key. They never
2346- // go back to being public once we've seen
2347- // '--extern-private', so we logical-AND
2348- // their current and new 'public' value together
2349-
23502341 externs
23512342 . entry ( name. to_owned ( ) )
2352- . or_default ( )
2353- . entry ( location)
2354- . and_modify ( |e| * e &= public)
2355- . or_insert ( public) ;
2356- }
2343+ . and_modify ( |e| {
2344+ e. locations . insert ( location. clone ( ) ) ;
2345+
2346+ // Crates start out being not private,
2347+ // and go to being private if we see an '--extern-private'
2348+ // flag
2349+ e. is_private_dep |= private;
2350+ } )
2351+ . or_insert_with ( || {
2352+ let mut locations = BTreeSet :: new ( ) ;
2353+ locations. insert ( location) ;
23572354
2358- // Now that we've determined the 'public' status of each extern,
2359- // collect them into a set of ExternEntry
2360- let externs: BTreeMap < String , BTreeSet < ExternEntry > > = externs. into_iter ( )
2361- . map ( |( k, v) | {
2362- let values =v. into_iter ( ) . map ( |( location, public) | {
23632355 ExternEntry {
2364- location ,
2365- public
2356+ locations : locations ,
2357+ is_private_dep : private
23662358 }
2367- } ) . collect :: < BTreeSet < ExternEntry > > ( ) ;
2368- ( k, values)
2369- } )
2370- . collect ( ) ;
2371-
2372-
2359+ } ) ;
2360+ }
23732361
23742362 let crate_name = matches. opt_str ( "crate-name" ) ;
23752363
@@ -2699,9 +2687,11 @@ mod tests {
26992687
27002688 impl ExternEntry {
27012689 fn new_public ( location : Option < String > ) -> ExternEntry {
2690+ let mut locations = BTreeSet :: new ( ) ;
2691+ locations. insert ( location) ;
27022692 ExternEntry {
2703- location ,
2704- public : true
2693+ locations ,
2694+ is_private_dep : false
27052695 }
27062696 }
27072697 }
0 commit comments