@@ -268,26 +268,24 @@ 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 < ExternEntry > > ) ;
271+ pub struct Externs ( BTreeMap < String , ExternEntry > ) ;
272272
273273#[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug ) ]
274274pub struct ExternEntry {
275- pub location : Option < String > ,
276- pub public : bool
275+ pub locations : BTreeSet < Option < String > > ,
276+ pub is_private_dep : bool
277277}
278278
279-
280-
281279impl Externs {
282- pub fn new ( data : BTreeMap < String , BTreeSet < ExternEntry > > ) -> Externs {
280+ pub fn new ( data : BTreeMap < String , ExternEntry > ) -> Externs {
283281 Externs ( data)
284282 }
285283
286- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < ExternEntry > > {
284+ pub fn get ( & self , key : & str ) -> Option < & ExternEntry > {
287285 self . 0 . get ( key)
288286 }
289287
290- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < ExternEntry > > {
288+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , ExternEntry > {
291289 self . 0 . iter ( )
292290 }
293291}
@@ -2296,9 +2294,9 @@ pub fn build_session_options_and_crate_config(
22962294 // and later convert it into a BTreeSet<(Option<String>, bool)>
22972295 // This allows to modify entries in-place to set their correct
22982296 // 'public' value
2299- let mut externs: BTreeMap < _ , BTreeMap < Option < String > , bool > > = BTreeMap :: new ( ) ;
2300- for ( arg, public ) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, true ) )
2301- . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, false ) ) ) {
2297+ let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
2298+ for ( arg, private ) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, false ) )
2299+ . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, true ) ) ) {
23022300
23032301 let mut parts = arg. splitn ( 2 , '=' ) ;
23042302 let name = parts. next ( ) . unwrap_or_else ( ||
@@ -2313,36 +2311,26 @@ pub fn build_session_options_and_crate_config(
23132311 } ;
23142312
23152313
2316- // Extern crates start out public,
2317- // and become private if we later see
2318- // an '--extern-private' key. They never
2319- // go back to being public once we've seen
2320- // '--extern-private', so we logical-AND
2321- // their current and new 'public' value together
2322-
23232314 externs
23242315 . entry ( name. to_owned ( ) )
2325- . or_default ( )
2326- . entry ( location)
2327- . and_modify ( |e| * e &= public)
2328- . or_insert ( public) ;
2329- }
2316+ . and_modify ( |e| {
2317+ e. locations . insert ( location. clone ( ) ) ;
2318+
2319+ // Crates start out being not private,
2320+ // and go to being private if we see an '--extern-private'
2321+ // flag
2322+ e. is_private_dep |= private;
2323+ } )
2324+ . or_insert_with ( || {
2325+ let mut locations = BTreeSet :: new ( ) ;
2326+ locations. insert ( location) ;
23302327
2331- // Now that we've determined the 'public' status of each extern,
2332- // collect them into a set of ExternEntry
2333- let externs: BTreeMap < String , BTreeSet < ExternEntry > > = externs. into_iter ( )
2334- . map ( |( k, v) | {
2335- let values =v. into_iter ( ) . map ( |( location, public) | {
23362328 ExternEntry {
2337- location ,
2338- public
2329+ locations : locations ,
2330+ is_private_dep : private
23392331 }
2340- } ) . collect :: < BTreeSet < ExternEntry > > ( ) ;
2341- ( k, values)
2342- } )
2343- . collect ( ) ;
2344-
2345-
2332+ } ) ;
2333+ }
23462334
23472335 let crate_name = matches. opt_str ( "crate-name" ) ;
23482336
@@ -2671,9 +2659,11 @@ mod tests {
26712659
26722660 impl ExternEntry {
26732661 fn new_public ( location : Option < String > ) -> ExternEntry {
2662+ let mut locations = BTreeSet :: new ( ) ;
2663+ locations. insert ( location) ;
26742664 ExternEntry {
2675- location ,
2676- public : true
2665+ locations ,
2666+ is_private_dep : false
26772667 }
26782668 }
26792669 }
0 commit comments