@@ -1970,14 +1970,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
1970
1970
self . arenas . alloc_module ( module)
1971
1971
}
1972
1972
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 {
1975
1976
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
+ }
1976
1988
used. set ( true ) ;
1977
1989
directive. used . set ( true ) ;
1978
1990
self . used_imports . insert ( ( directive. id , ns) ) ;
1979
1991
self . add_to_glob_map ( directive. id , ident) ;
1980
- self . record_use ( ident, ns, binding) ;
1992
+ self . record_use ( ident, ns, binding, false ) ;
1981
1993
}
1982
1994
NameBindingKind :: Ambiguity { kind, b1, b2 } => {
1983
1995
self . ambiguity_errors . push ( AmbiguityError {
@@ -2965,7 +2977,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2965
2977
Def :: Const ( ..) if is_syntactic_ambiguity => {
2966
2978
// Disambiguate in favor of a unit struct/variant
2967
2979
// or constant pattern.
2968
- self . record_use ( ident, ValueNS , binding. unwrap ( ) ) ;
2980
+ self . record_use ( ident, ValueNS , binding. unwrap ( ) , false ) ;
2969
2981
Some ( PathResolution :: new ( def) )
2970
2982
}
2971
2983
Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
0 commit comments