@@ -1487,13 +1487,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14871487 let mut invocation_parents = FxHashMap :: default ( ) ;
14881488 invocation_parents. insert ( LocalExpnId :: ROOT , InvocationParent :: ROOT ) ;
14891489
1490- let mut extern_prelude: FxIndexMap < Ident , ExternPreludeEntry < ' _ > > = tcx
1490+ let mut extern_prelude: FxIndexMap < _ , _ > = tcx
14911491 . sess
14921492 . opts
14931493 . externs
14941494 . iter ( )
1495- . filter ( |( _, entry) | entry. add_prelude )
1496- . map ( |( name, _) | ( Ident :: from_str ( name) , Default :: default ( ) ) )
1495+ . filter_map ( |( name, entry) | {
1496+ // Make sure `self`, `super`, `_` etc do not get into extern prelude.
1497+ // FIXME: reject `--extern self` and similar in option parsing instead.
1498+ if entry. add_prelude
1499+ && let name = Symbol :: intern ( name)
1500+ && name. can_be_raw ( )
1501+ {
1502+ Some ( ( Ident :: with_dummy_span ( name) , Default :: default ( ) ) )
1503+ } else {
1504+ None
1505+ }
1506+ } )
14971507 . collect ( ) ;
14981508
14991509 if !attr:: contains_name ( attrs, sym:: no_core) {
@@ -2168,40 +2178,42 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21682178 }
21692179
21702180 fn extern_prelude_get ( & mut self , ident : Ident , finalize : bool ) -> Option < NameBinding < ' ra > > {
2171- if ident. is_path_segment_keyword ( ) {
2172- // Make sure `self`, `super` etc produce an error when passed to here.
2173- return None ;
2174- }
2175-
2176- let norm_ident = ident. normalize_to_macros_2_0 ( ) ;
2177- let binding = self . extern_prelude . get ( & norm_ident) . cloned ( ) . and_then ( |entry| {
2178- 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 ( ) => {
21792185 if finalize {
2180- if !entry. is_import ( ) {
2181- self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span ) ;
2182- } else if entry. introduced_by_item {
2183- self . record_use ( ident, binding, Used :: Other ) ;
2184- }
2186+ record_use = Some ( binding) ;
21852187 }
2186- binding
2187- } 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 => {
21882197 let crate_id = if finalize {
2189- let Some ( crate_id) =
2190- self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span )
2191- else {
2192- return Some ( self . dummy_binding ) ;
2193- } ;
2194- crate_id
2198+ self . cstore_mut ( ) . process_path_extern ( self . tcx , ident. name , ident. span )
21952199 } else {
2196- self . cstore_mut ( ) . maybe_process_path_extern ( self . tcx , ident. name ) ?
2200+ self . cstore_mut ( ) . maybe_process_path_extern ( self . tcx , ident. name )
21972201 } ;
2198- let res = Res :: Def ( DefKind :: Mod , crate_id. as_def_id ( ) ) ;
2199- self . arenas . new_pub_res_binding ( res, DUMMY_SP , LocalExpnId :: ROOT )
2200- } )
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+ }
22012213 } ) ;
22022214
2203- if let Some ( entry ) = self . extern_prelude . get ( & norm_ident ) {
2204- entry . binding . set ( binding) ;
2215+ if let Some ( binding ) = record_use {
2216+ self . record_use ( ident , binding, Used :: Scope ) ;
22052217 }
22062218
22072219 binding
0 commit comments