@@ -885,10 +885,16 @@ impl<'a> NameBindingData<'a> {
885
885
886
886
#[ derive( Default , Clone ) ]
887
887
struct ExternPreludeEntry < ' a > {
888
- extern_crate_item : Option < NameBinding < ' a > > ,
888
+ binding : Option < NameBinding < ' a > > ,
889
889
introduced_by_item : bool ,
890
890
}
891
891
892
+ impl ExternPreludeEntry < ' _ > {
893
+ fn is_import ( & self ) -> bool {
894
+ self . binding . is_some_and ( |binding| binding. is_import ( ) )
895
+ }
896
+ }
897
+
892
898
/// Used for better errors for E0773
893
899
enum BuiltinMacroState {
894
900
NotYetSeen ( SyntaxExtensionKind ) ,
@@ -1742,7 +1748,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1742
1748
// but not introduce it, as used if they are accessed from lexical scope.
1743
1749
if is_lexical_scope {
1744
1750
if let Some ( entry) = self . extern_prelude . get ( & ident. normalize_to_macros_2_0 ( ) ) {
1745
- if !entry. introduced_by_item && entry. extern_crate_item == Some ( used_binding) {
1751
+ if !entry. introduced_by_item && entry. binding == Some ( used_binding) {
1746
1752
return ;
1747
1753
}
1748
1754
}
@@ -1900,12 +1906,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1900
1906
// Make sure `self`, `super` etc produce an error when passed to here.
1901
1907
return None ;
1902
1908
}
1903
- self . extern_prelude . get ( & ident. normalize_to_macros_2_0 ( ) ) . cloned ( ) . and_then ( |entry| {
1904
- if let Some ( binding) = entry. extern_crate_item {
1905
- if finalize && entry. introduced_by_item {
1906
- self . record_use ( ident, binding, false ) ;
1909
+
1910
+ let norm_ident = ident. normalize_to_macros_2_0 ( ) ;
1911
+ let binding = self . extern_prelude . get ( & norm_ident) . cloned ( ) . and_then ( |entry| {
1912
+ Some ( if let Some ( binding) = entry. binding {
1913
+ if finalize {
1914
+ if !entry. is_import ( ) {
1915
+ self . crate_loader ( |c| c. process_path_extern ( ident. name , ident. span ) ) ;
1916
+ } else if entry. introduced_by_item {
1917
+ self . record_use ( ident, binding, false ) ;
1918
+ }
1907
1919
}
1908
- Some ( binding)
1920
+ binding
1909
1921
} else {
1910
1922
let crate_id = if finalize {
1911
1923
let Some ( crate_id) =
@@ -1918,10 +1930,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1918
1930
self . crate_loader ( |c| c. maybe_process_path_extern ( ident. name ) ) ?
1919
1931
} ;
1920
1932
let crate_root = self . expect_module ( crate_id. as_def_id ( ) ) ;
1921
- let vis = ty:: Visibility :: < LocalDefId > :: Public ;
1922
- Some ( ( crate_root, vis, DUMMY_SP , LocalExpnId :: ROOT ) . to_name_binding ( self . arenas ) )
1923
- }
1924
- } )
1933
+ let vis = ty:: Visibility :: < DefId > :: Public ;
1934
+ ( crate_root, vis, DUMMY_SP , LocalExpnId :: ROOT ) . to_name_binding ( self . arenas )
1935
+ } )
1936
+ } ) ;
1937
+
1938
+ if let Some ( entry) = self . extern_prelude . get_mut ( & norm_ident) {
1939
+ entry. binding = binding;
1940
+ }
1941
+
1942
+ binding
1925
1943
}
1926
1944
1927
1945
/// Rustdoc uses this to resolve doc link paths in a recoverable way. `PathResult<'a>`
0 commit comments