@@ -1031,7 +1031,7 @@ struct ExternPreludeEntry<'ra> {
1031
1031
/// `flag_binding` is `None`, or when `extern crate` introducing `item_binding` used renaming.
1032
1032
item_binding: Option<(NameBinding<'ra>, /* introduced by item */ bool)>,
1033
1033
/// Binding from an `--extern` flag, lazily populated on first use.
1034
- flag_binding: Option<Cell<PendingBinding<'ra>>>,
1034
+ flag_binding: Option<Cell<( PendingBinding<'ra>, /* finalized */ bool) >>,
1035
1035
}
1036
1036
1037
1037
impl ExternPreludeEntry<'_> {
@@ -1042,7 +1042,7 @@ impl ExternPreludeEntry<'_> {
1042
1042
fn flag() -> Self {
1043
1043
ExternPreludeEntry {
1044
1044
item_binding: None,
1045
- flag_binding: Some(Cell::new(PendingBinding::Pending)),
1045
+ flag_binding: Some(Cell::new(( PendingBinding::Pending, false) )),
1046
1046
}
1047
1047
}
1048
1048
}
@@ -2245,14 +2245,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2245
2245
fn extern_prelude_get_flag(&self, ident: Ident, finalize: bool) -> Option<NameBinding<'ra>> {
2246
2246
let entry = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident));
2247
2247
entry.and_then(|entry| entry.flag_binding.as_ref()).and_then(|flag_binding| {
2248
- let binding = match flag_binding.get() {
2248
+ let (pending_binding, finalized) = flag_binding.get();
2249
+ let binding = match pending_binding {
2249
2250
PendingBinding::Ready(binding) => {
2250
- if finalize {
2251
+ if finalize && !finalized {
2251
2252
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span);
2252
2253
}
2253
2254
binding
2254
2255
}
2255
2256
PendingBinding::Pending => {
2257
+ debug_assert!(!finalized);
2256
2258
let crate_id = if finalize {
2257
2259
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span)
2258
2260
} else {
@@ -2264,7 +2266,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2264
2266
})
2265
2267
}
2266
2268
};
2267
- flag_binding.set(PendingBinding::Ready(binding));
2269
+ flag_binding.set(( PendingBinding::Ready(binding), finalize || finalized ));
2268
2270
binding.or_else(|| finalize.then_some(self.dummy_binding))
2269
2271
})
2270
2272
}
0 commit comments