@@ -1911,14 +1911,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
19111911 self . arenas . alloc_module ( module)
19121912 }
19131913
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 {
19161917 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+ }
19171929 used. set ( true ) ;
19181930 directive. used . set ( true ) ;
19191931 self . used_imports . insert ( ( directive. id , ns) ) ;
19201932 self . add_to_glob_map ( directive. id , ident) ;
1921- self . record_use ( ident, ns, binding) ;
1933+ self . record_use ( ident, ns, binding, false ) ;
19221934 }
19231935 NameBindingKind :: Ambiguity { kind, b1, b2 } => {
19241936 self . ambiguity_errors . push ( AmbiguityError {
@@ -2908,7 +2920,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
29082920 Def :: Const ( ..) if is_syntactic_ambiguity => {
29092921 // Disambiguate in favor of a unit struct/variant
29102922 // or constant pattern.
2911- self . record_use ( ident, ValueNS , binding. unwrap ( ) ) ;
2923+ self . record_use ( ident, ValueNS , binding. unwrap ( ) , false ) ;
29122924 Some ( PathResolution :: new ( def) )
29132925 }
29142926 Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
0 commit comments