@@ -105,24 +105,41 @@ fn try_resolve_did(tcx: TyCtxt<'_>, path: &[&str], namespace: Option<Namespace>)
105105        ( path,  None ) 
106106    } ; 
107107
108-     // First find the crate. 
109-     let  krate =
110-         tcx. crates ( ( ) ) . iter ( ) . find ( |& & krate| tcx. crate_name ( krate) . as_str ( )  == crate_name) ?; 
111-     let  mut  cur_item = DefId  {  krate :  * krate,  index :  CRATE_DEF_INDEX  } ; 
112-     // Then go over the modules. 
113-     for  & segment in  modules { 
114-         cur_item = find_children ( tcx,  cur_item,  segment) 
115-             . find ( |item| tcx. def_kind ( item)  == DefKind :: Mod ) ?; 
116-     } 
117-     // Finally, look up the desired item in this module, if any. 
118-     match  item { 
119-         Some ( ( item_name,  namespace) )  =>
120-             Some ( 
121-                 find_children ( tcx,  cur_item,  item_name) 
122-                     . find ( |item| tcx. def_kind ( item) . ns ( )  == Some ( namespace) ) ?, 
123-             ) , 
124-         None  => Some ( cur_item) , 
108+     // There may be more than one crate with this name. We try them all. 
109+     // (This is particularly relevant when running `std` tests as then there are two `std` crates: 
110+     // the one in the sysroot and the one locally built by `cargo test`.) 
111+     // FIXME: can we prefer the one from the sysroot? 
112+     ' crates:  for  krate in 
113+         tcx. crates ( ( ) ) . iter ( ) . filter ( |& & krate| tcx. crate_name ( krate) . as_str ( )  == crate_name) 
114+     { 
115+         let  mut  cur_item = DefId  {  krate :  * krate,  index :  CRATE_DEF_INDEX  } ; 
116+         // Go over the modules. 
117+         for  & segment in  modules { 
118+             let  Some ( next_item)  = find_children ( tcx,  cur_item,  segment) 
119+                 . find ( |item| tcx. def_kind ( item)  == DefKind :: Mod ) 
120+             else  { 
121+                 continue  ' crates; 
122+             } ; 
123+             cur_item = next_item; 
124+         } 
125+         // Finally, look up the desired item in this module, if any. 
126+         match  item { 
127+             Some ( ( item_name,  namespace) )  => { 
128+                 let  Some ( item)  = find_children ( tcx,  cur_item,  item_name) 
129+                     . find ( |item| tcx. def_kind ( item) . ns ( )  == Some ( namespace) ) 
130+                 else  { 
131+                     continue  ' crates; 
132+                 } ; 
133+                 return  Some ( item) ; 
134+             } 
135+             None  => { 
136+                 // Just return the module. 
137+                 return  Some ( cur_item) ; 
138+             } 
139+         } 
125140    } 
141+     // Item not found in any of the crates with the right name. 
142+     None 
126143} 
127144
128145/// Convert a softfloat type to its corresponding hostfloat type. 
0 commit comments