@@ -2178,35 +2178,42 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21782178 }
21792179
21802180 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 ( ) => {
21842185 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) ;
21902187 }
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 => {
21932197 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 )
22002199 } 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 )
22022201 } ;
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+ }
22062213 } ) ;
22072214
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 ) ;
22102217 }
22112218
22122219 binding
0 commit comments