@@ -2178,35 +2178,42 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2178
2178
}
2179
2179
2180
2180
fn extern_prelude_get ( & mut self , ident : Ident , finalize : bool ) -> Option < NameBinding < ' ra > > {
2181
- let norm_ident = ident. normalize_to_macros_2_0 ( ) ;
2182
- let binding = self . extern_prelude . get ( & norm_ident) . cloned ( ) . and_then ( |entry| {
2183
- Some ( if let Some ( binding) = entry. binding . get ( ) {
2181
+ let mut record_use = None ;
2182
+ let entry = self . extern_prelude . get ( & ident. normalize_to_macros_2_0 ( ) ) ;
2183
+ let binding = entry. and_then ( |entry| match entry. binding . get ( ) {
2184
+ Some ( binding) if binding. is_import ( ) => {
2184
2185
if finalize {
2185
- if !entry. is_import ( ) {
2186
- self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span ) ;
2187
- } else if entry. introduced_by_item {
2188
- self . record_use ( ident, binding, Used :: Other ) ;
2189
- }
2186
+ record_use = Some ( binding) ;
2190
2187
}
2191
- binding
2192
- } else {
2188
+ Some ( binding)
2189
+ }
2190
+ Some ( binding) => {
2191
+ if finalize {
2192
+ self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span ) ;
2193
+ }
2194
+ Some ( binding)
2195
+ }
2196
+ None => {
2193
2197
let crate_id = if finalize {
2194
- let Some ( crate_id) =
2195
- self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span )
2196
- else {
2197
- return Some ( self . dummy_binding ) ;
2198
- } ;
2199
- crate_id
2198
+ self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span )
2200
2199
} else {
2201
- self . cstore_mut ( ) . maybe_process_path_extern ( self . tcx , ident. name ) ?
2200
+ self . cstore_mut ( ) . maybe_process_path_extern ( self . tcx , ident. name )
2202
2201
} ;
2203
- let res = Res :: Def ( DefKind :: Mod , crate_id. as_def_id ( ) ) ;
2204
- self . arenas . new_pub_res_binding ( res, DUMMY_SP , LocalExpnId :: ROOT )
2205
- } )
2202
+ match crate_id {
2203
+ Some ( crate_id) => {
2204
+ let res = Res :: Def ( DefKind :: Mod , crate_id. as_def_id ( ) ) ;
2205
+ let binding =
2206
+ self . arenas . new_pub_res_binding ( res, DUMMY_SP , LocalExpnId :: ROOT ) ;
2207
+ entry. binding . set ( Some ( binding) ) ;
2208
+ Some ( binding)
2209
+ }
2210
+ None => finalize. then_some ( self . dummy_binding ) ,
2211
+ }
2212
+ }
2206
2213
} ) ;
2207
2214
2208
- if let Some ( entry ) = self . extern_prelude . get ( & norm_ident ) {
2209
- entry . binding . set ( binding) ;
2215
+ if let Some ( binding ) = record_use {
2216
+ self . record_use ( ident , binding, Used :: Scope ) ;
2210
2217
}
2211
2218
2212
2219
binding
0 commit comments