@@ -42,9 +42,10 @@ use std::{mem, ptr};
42
42
#[ derive( Clone , Debug ) ]
43
43
pub enum ImportDirectiveSubclass < ' a > {
44
44
SingleImport {
45
- target : Ident ,
46
45
source : Ident ,
47
- result : PerNS < Cell < Result < & ' a NameBinding < ' a > , Determinacy > > > ,
46
+ target : Ident ,
47
+ source_bindings : PerNS < Cell < Result < & ' a NameBinding < ' a > , Determinacy > > > ,
48
+ target_bindings : PerNS < Cell < Option < & ' a NameBinding < ' a > > > > ,
48
49
type_ns_only : bool ,
49
50
} ,
50
51
GlobImport {
@@ -227,6 +228,11 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
227
228
}
228
229
229
230
let check_usable = |this : & mut Self , binding : & ' a NameBinding < ' a > | {
231
+ if let Some ( blacklisted_binding) = this. blacklisted_binding {
232
+ if ptr:: eq ( binding, blacklisted_binding) {
233
+ return Err ( ( Determined , Weak :: No ) ) ;
234
+ }
235
+ }
230
236
// `extern crate` are always usable for backwards compatibility, see issue #37020,
231
237
// remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
232
238
let usable = this. is_accessible ( binding. vis ) || binding. is_extern_crate ( ) ;
@@ -642,10 +648,10 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
642
648
if let Some ( ( span, err, note) ) = self . finalize_import ( import) {
643
649
errors = true ;
644
650
645
- if let SingleImport { source, ref result , .. } = import. subclass {
651
+ if let SingleImport { source, ref source_bindings , .. } = import. subclass {
646
652
if source. name == "self" {
647
653
// Silence `unresolved import` error if E0429 is already emitted
648
- if let Err ( Determined ) = result . value_ns . get ( ) {
654
+ if let Err ( Determined ) = source_bindings . value_ns . get ( ) {
649
655
continue ;
650
656
}
651
657
}
@@ -765,9 +771,11 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
765
771
} ;
766
772
767
773
directive. imported_module . set ( Some ( module) ) ;
768
- let ( source, target, result, type_ns_only) = match directive. subclass {
769
- SingleImport { source, target, ref result, type_ns_only } =>
770
- ( source, target, result, type_ns_only) ,
774
+ let ( source, target, source_bindings, target_bindings, type_ns_only) =
775
+ match directive. subclass {
776
+ SingleImport { source, target, ref source_bindings,
777
+ ref target_bindings, type_ns_only } =>
778
+ ( source, target, source_bindings, target_bindings, type_ns_only) ,
771
779
GlobImport { .. } => {
772
780
self . resolve_glob_import ( directive) ;
773
781
return true ;
@@ -777,7 +785,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
777
785
778
786
let mut indeterminate = false ;
779
787
self . per_ns ( |this, ns| if !type_ns_only || ns == TypeNS {
780
- if let Err ( Undetermined ) = result [ ns] . get ( ) {
788
+ if let Err ( Undetermined ) = source_bindings [ ns] . get ( ) {
781
789
// For better failure detection, pretend that the import will
782
790
// not define any names while resolving its module path.
783
791
let orig_vis = directive. vis . replace ( ty:: Visibility :: Invisible ) ;
@@ -786,13 +794,13 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
786
794
) ;
787
795
directive. vis . set ( orig_vis) ;
788
796
789
- result [ ns] . set ( binding) ;
797
+ source_bindings [ ns] . set ( binding) ;
790
798
} else {
791
799
return
792
800
} ;
793
801
794
802
let parent = directive. parent_scope . module ;
795
- match result [ ns] . get ( ) {
803
+ match source_bindings [ ns] . get ( ) {
796
804
Err ( Undetermined ) => indeterminate = true ,
797
805
Err ( Determined ) => {
798
806
this. update_resolution ( parent, target, ns, |_, resolution| {
@@ -810,6 +818,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
810
818
}
811
819
Ok ( binding) => {
812
820
let imported_binding = this. import ( binding, directive) ;
821
+ target_bindings[ ns] . set ( Some ( imported_binding) ) ;
813
822
let conflict = this. try_define ( parent, target, ns, imported_binding) ;
814
823
if let Err ( old_binding) = conflict {
815
824
this. report_conflict ( parent, target, ns, imported_binding, old_binding) ;
@@ -879,8 +888,9 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
879
888
PathResult :: Indeterminate | PathResult :: NonModule ( ..) => unreachable ! ( ) ,
880
889
} ;
881
890
882
- let ( ident, result, type_ns_only) = match directive. subclass {
883
- SingleImport { source, ref result, type_ns_only, .. } => ( source, result, type_ns_only) ,
891
+ let ( ident, source_bindings, target_bindings, type_ns_only) = match directive. subclass {
892
+ SingleImport { source, ref source_bindings, ref target_bindings, type_ns_only, .. } =>
893
+ ( source, source_bindings, target_bindings, type_ns_only) ,
884
894
GlobImport { is_prelude, ref max_vis } => {
885
895
if directive. module_path . len ( ) <= 1 {
886
896
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
@@ -919,17 +929,20 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
919
929
let mut all_ns_err = true ;
920
930
self . per_ns ( |this, ns| if !type_ns_only || ns == TypeNS {
921
931
let orig_vis = directive. vis . replace ( ty:: Visibility :: Invisible ) ;
932
+ let orig_blacklisted_binding =
933
+ mem:: replace ( & mut this. blacklisted_binding , target_bindings[ ns] . get ( ) ) ;
922
934
let orig_last_import_segment = mem:: replace ( & mut this. last_import_segment , true ) ;
923
935
let binding = this. resolve_ident_in_module (
924
936
module, ident, ns, Some ( & directive. parent_scope ) , true , directive. span
925
937
) ;
926
938
this. last_import_segment = orig_last_import_segment;
939
+ this. blacklisted_binding = orig_blacklisted_binding;
927
940
directive. vis . set ( orig_vis) ;
928
941
929
942
match binding {
930
943
Ok ( binding) => {
931
944
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
932
- let initial_def = result [ ns] . get ( ) . map ( |initial_binding| {
945
+ let initial_def = source_bindings [ ns] . get ( ) . map ( |initial_binding| {
933
946
all_ns_err = false ;
934
947
this. record_use ( ident, ns, initial_binding,
935
948
directive. module_path . is_empty ( ) ) ;
@@ -1034,7 +1047,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1034
1047
let mut reexport_error = None ;
1035
1048
let mut any_successful_reexport = false ;
1036
1049
self . per_ns ( |this, ns| {
1037
- if let Ok ( binding) = result [ ns] . get ( ) {
1050
+ if let Ok ( binding) = source_bindings [ ns] . get ( ) {
1038
1051
let vis = directive. vis . get ( ) ;
1039
1052
if !binding. pseudo_vis ( ) . is_at_least ( vis, & * this) {
1040
1053
reexport_error = Some ( ( ns, binding) ) ;
@@ -1078,7 +1091,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1078
1091
let mut full_path = directive. module_path . clone ( ) ;
1079
1092
full_path. push ( Segment :: from_ident ( ident) ) ;
1080
1093
self . per_ns ( |this, ns| {
1081
- if let Ok ( binding) = result [ ns] . get ( ) {
1094
+ if let Ok ( binding) = source_bindings [ ns] . get ( ) {
1082
1095
this. lint_if_path_starts_with_module (
1083
1096
directive. crate_lint ( ) ,
1084
1097
& full_path,
@@ -1092,7 +1105,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1092
1105
// Record what this import resolves to for later uses in documentation,
1093
1106
// this may resolve to either a value or a type, but for documentation
1094
1107
// purposes it's good enough to just favor one over the other.
1095
- self . per_ns ( |this, ns| if let Some ( binding) = result [ ns] . get ( ) . ok ( ) {
1108
+ self . per_ns ( |this, ns| if let Some ( binding) = source_bindings [ ns] . get ( ) . ok ( ) {
1096
1109
let mut def = binding. def ( ) ;
1097
1110
if let Def :: Macro ( def_id, _) = def {
1098
1111
// `DefId`s from the "built-in macro crate" should not leak from resolve because
0 commit comments