@@ -1970,14 +1970,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
19701970 self . arenas . alloc_module ( module)
19711971 }
19721972
1973- fn record_use ( & mut self , ident : Ident , ns : Namespace , binding : & ' a NameBinding < ' a > ) {
1974- match binding. kind {
1973+ fn record_use ( & mut self , ident : Ident , ns : Namespace ,
1974+ used_binding : & ' a NameBinding < ' a > , is_lexical_scope : bool ) {
1975+ match used_binding. kind {
19751976 NameBindingKind :: Import { directive, binding, ref used } if !used. get ( ) => {
1977+ // Avoid marking `extern crate` items that refer to a name from extern prelude,
1978+ // but not introduce it, as used if they are accessed from lexical scope.
1979+ if is_lexical_scope {
1980+ if let Some ( entry) = self . extern_prelude . get ( & ident. modern ( ) ) {
1981+ if let Some ( crate_item) = entry. extern_crate_item {
1982+ if ptr:: eq ( used_binding, crate_item) && !entry. introduced_by_item {
1983+ return ;
1984+ }
1985+ }
1986+ }
1987+ }
19761988 used. set ( true ) ;
19771989 directive. used . set ( true ) ;
19781990 self . used_imports . insert ( ( directive. id , ns) ) ;
19791991 self . add_to_glob_map ( directive. id , ident) ;
1980- self . record_use ( ident, ns, binding) ;
1992+ self . record_use ( ident, ns, binding, false ) ;
19811993 }
19821994 NameBindingKind :: Ambiguity { kind, b1, b2 } => {
19831995 self . ambiguity_errors . push ( AmbiguityError {
@@ -2965,7 +2977,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
29652977 Def :: Const ( ..) if is_syntactic_ambiguity => {
29662978 // Disambiguate in favor of a unit struct/variant
29672979 // or constant pattern.
2968- self . record_use ( ident, ValueNS , binding. unwrap ( ) ) ;
2980+ self . record_use ( ident, ValueNS , binding. unwrap ( ) , false ) ;
29692981 Some ( PathResolution :: new ( def) )
29702982 }
29712983 Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
0 commit comments