@@ -1911,14 +1911,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
1911
1911
self . arenas . alloc_module ( module)
1912
1912
}
1913
1913
1914
- fn record_use ( & mut self , ident : Ident , ns : Namespace , binding : & ' a NameBinding < ' a > ) {
1915
- match binding. kind {
1914
+ fn record_use ( & mut self , ident : Ident , ns : Namespace ,
1915
+ used_binding : & ' a NameBinding < ' a > , is_lexical_scope : bool ) {
1916
+ match used_binding. kind {
1916
1917
NameBindingKind :: Import { directive, binding, ref used } if !used. get ( ) => {
1918
+ // Avoid marking `extern crate` items that refer to a name from extern prelude,
1919
+ // but not introduce it, as used if they are accessed from lexical scope.
1920
+ if is_lexical_scope {
1921
+ if let Some ( entry) = self . extern_prelude . get ( & ident. modern ( ) ) {
1922
+ if let Some ( crate_item) = entry. extern_crate_item {
1923
+ if ptr:: eq ( used_binding, crate_item) && !entry. introduced_by_item {
1924
+ return ;
1925
+ }
1926
+ }
1927
+ }
1928
+ }
1917
1929
used. set ( true ) ;
1918
1930
directive. used . set ( true ) ;
1919
1931
self . used_imports . insert ( ( directive. id , ns) ) ;
1920
1932
self . add_to_glob_map ( directive. id , ident) ;
1921
- self . record_use ( ident, ns, binding) ;
1933
+ self . record_use ( ident, ns, binding, false ) ;
1922
1934
}
1923
1935
NameBindingKind :: Ambiguity { kind, b1, b2 } => {
1924
1936
self . ambiguity_errors . push ( AmbiguityError {
@@ -2908,7 +2920,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2908
2920
Def :: Const ( ..) if is_syntactic_ambiguity => {
2909
2921
// Disambiguate in favor of a unit struct/variant
2910
2922
// or constant pattern.
2911
- self . record_use ( ident, ValueNS , binding. unwrap ( ) ) ;
2923
+ self . record_use ( ident, ValueNS , binding. unwrap ( ) , false ) ;
2912
2924
Some ( PathResolution :: new ( def) )
2913
2925
}
2914
2926
Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
0 commit comments