@@ -1487,13 +1487,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1487
1487
let mut invocation_parents = FxHashMap :: default ( ) ;
1488
1488
invocation_parents. insert ( LocalExpnId :: ROOT , InvocationParent :: ROOT ) ;
1489
1489
1490
- let mut extern_prelude: FxIndexMap < Ident , ExternPreludeEntry < ' _ > > = tcx
1490
+ let mut extern_prelude: FxIndexMap < _ , _ > = tcx
1491
1491
. sess
1492
1492
. opts
1493
1493
. externs
1494
1494
. 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
+ } )
1497
1507
. collect ( ) ;
1498
1508
1499
1509
if !attr:: contains_name ( attrs, sym:: no_core) {
@@ -2168,40 +2178,42 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2168
2178
}
2169
2179
2170
2180
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 ( ) => {
2179
2185
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) ;
2185
2187
}
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 => {
2188
2197
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 )
2195
2199
} 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 )
2197
2201
} ;
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
+ }
2201
2213
} ) ;
2202
2214
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 ) ;
2205
2217
}
2206
2218
2207
2219
binding
0 commit comments