@@ -345,9 +345,6 @@ impl Rib {
345
345
#[ deriving( Show , PartialEq , Clone , Copy ) ]
346
346
enum Shadowable {
347
347
Always ,
348
- /// Means that the recorded import obeys the glob shadowing rules, i.e., can
349
- /// only be shadowed by another glob import.
350
- Glob ,
351
348
Never
352
349
}
353
350
@@ -462,6 +459,22 @@ impl ImportResolution {
462
459
463
460
target. unwrap ( ) . shadowable
464
461
}
462
+
463
+ fn set_target_and_id ( & mut self ,
464
+ namespace : Namespace ,
465
+ target : Option < Target > ,
466
+ id : NodeId ) {
467
+ match namespace {
468
+ TypeNS => {
469
+ self . type_target = target;
470
+ self . type_id = id;
471
+ }
472
+ ValueNS => {
473
+ self . value_target = target;
474
+ self . value_id = id;
475
+ }
476
+ }
477
+ }
465
478
}
466
479
467
480
/// The link from a module up to its nearest parent node.
@@ -1719,11 +1732,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1719
1732
view_path. span ,
1720
1733
id,
1721
1734
is_public,
1722
- if shadowable == Shadowable :: Never {
1723
- Shadowable :: Glob
1724
- } else {
1725
- shadowable
1726
- } ) ;
1735
+ shadowable) ;
1727
1736
}
1728
1737
}
1729
1738
}
@@ -2712,64 +2721,45 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2712
2721
// We've successfully resolved the import. Write the results in.
2713
2722
let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
2714
2723
let import_resolution = & mut ( * import_resolutions) [ target] ;
2724
+ {
2725
+ let check_and_write_import = |namespace, result : & _ , used_public : & mut bool | {
2726
+ let namespace_name = match namespace {
2727
+ TypeNS => "type" ,
2728
+ ValueNS => "value" ,
2729
+ } ;
2715
2730
2716
- match value_result {
2717
- BoundResult ( ref target_module, ref name_bindings) => {
2718
- debug ! ( "(resolving single import) found value target: {}" ,
2719
- { name_bindings. value_def. borrow( ) . clone( ) . unwrap( ) . def } ) ;
2720
- self . check_for_conflicting_import (
2721
- & import_resolution. value_target ,
2722
- directive. span ,
2723
- target,
2724
- ValueNS ) ;
2725
-
2726
- self . check_that_import_is_importable (
2727
- & * * name_bindings,
2728
- directive. span ,
2729
- target,
2730
- ValueNS ) ;
2731
-
2732
- import_resolution. value_target =
2733
- Some ( Target :: new ( target_module. clone ( ) ,
2734
- name_bindings. clone ( ) ,
2735
- directive. shadowable ) ) ;
2736
- import_resolution. value_id = directive. id ;
2737
- import_resolution. is_public = directive. is_public ;
2738
- value_used_public = name_bindings. defined_in_public_namespace ( ValueNS ) ;
2739
- }
2740
- UnboundResult => { /* Continue. */ }
2741
- UnknownResult => {
2742
- panic ! ( "value result should be known at this point" ) ;
2743
- }
2744
- }
2745
- match type_result {
2746
- BoundResult ( ref target_module, ref name_bindings) => {
2747
- debug ! ( "(resolving single import) found type target: {}" ,
2748
- { name_bindings. type_def. borrow( ) . clone( ) . unwrap( ) . type_def } ) ;
2749
- self . check_for_conflicting_import (
2750
- & import_resolution. type_target ,
2751
- directive. span ,
2752
- target,
2753
- TypeNS ) ;
2754
-
2755
- self . check_that_import_is_importable (
2756
- & * * name_bindings,
2757
- directive. span ,
2758
- target,
2759
- TypeNS ) ;
2760
-
2761
- import_resolution. type_target =
2762
- Some ( Target :: new ( target_module. clone ( ) ,
2763
- name_bindings. clone ( ) ,
2764
- directive. shadowable ) ) ;
2765
- import_resolution. type_id = directive. id ;
2766
- import_resolution. is_public = directive. is_public ;
2767
- type_used_public = name_bindings. defined_in_public_namespace ( TypeNS ) ;
2768
- }
2769
- UnboundResult => { /* Continue. */ }
2770
- UnknownResult => {
2771
- panic ! ( "type result should be known at this point" ) ;
2772
- }
2731
+ match * result {
2732
+ BoundResult ( ref target_module, ref name_bindings) => {
2733
+ debug ! ( "(resolving single import) found {} target: {}" ,
2734
+ namespace_name,
2735
+ name_bindings. def_for_namespace( namespace) ) ;
2736
+ self . check_for_conflicting_import (
2737
+ & import_resolution. target_for_namespace ( namespace) ,
2738
+ directive. span ,
2739
+ target,
2740
+ namespace) ;
2741
+
2742
+ self . check_that_import_is_importable (
2743
+ & * * name_bindings,
2744
+ directive. span ,
2745
+ target,
2746
+ namespace) ;
2747
+
2748
+ let target = Some ( Target :: new ( target_module. clone ( ) ,
2749
+ name_bindings. clone ( ) ,
2750
+ directive. shadowable ) ) ;
2751
+ import_resolution. set_target_and_id ( namespace, target, directive. id ) ;
2752
+ import_resolution. is_public = directive. is_public ;
2753
+ * used_public = name_bindings. defined_in_public_namespace ( namespace) ;
2754
+ }
2755
+ UnboundResult => { /* Continue. */ }
2756
+ UnknownResult => {
2757
+ panic ! ( "{} result should be known at this point" , namespace_name) ;
2758
+ }
2759
+ }
2760
+ } ;
2761
+ check_and_write_import ( ValueNS , & value_result, & mut value_used_public) ;
2762
+ check_and_write_import ( TypeNS , & type_result, & mut type_used_public) ;
2773
2763
}
2774
2764
2775
2765
self . check_for_conflicts_between_imports_and_items (
@@ -2825,7 +2815,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2825
2815
2826
2816
// Resolves a glob import. Note that this function cannot fail; it either
2827
2817
// succeeds or bails out (as importing * from an empty module or a module
2828
- // that exports nothing is valid).
2818
+ // that exports nothing is valid). containing_module is the module we are
2819
+ // actually importing, i.e., `foo` in `use foo::*`.
2829
2820
fn resolve_glob_import ( & mut self ,
2830
2821
module_ : & Module ,
2831
2822
containing_module : Rc < Module > ,
@@ -2851,12 +2842,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2851
2842
assert_eq ! ( containing_module. glob_count. get( ) , 0 ) ;
2852
2843
2853
2844
// Add all resolved imports from the containing module.
2854
- let import_resolutions = containing_module. import_resolutions
2855
- . borrow ( ) ;
2845
+ let import_resolutions = containing_module. import_resolutions . borrow ( ) ;
2856
2846
for ( ident, target_import_resolution) in import_resolutions. iter ( ) {
2857
2847
debug ! ( "(resolving glob import) writing module resolution \
2858
2848
{} into `{}`",
2859
- target_import_resolution . type_target . is_none ( ) ,
2849
+ token :: get_name ( * ident ) ,
2860
2850
self . module_to_string( module_) ) ;
2861
2851
2862
2852
if !target_import_resolution. is_public {
@@ -2876,17 +2866,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2876
2866
// Continue.
2877
2867
}
2878
2868
Some ( ref value_target) => {
2879
- dest_import_resolution. value_target =
2880
- Some ( value_target. clone ( ) ) ;
2869
+ self . check_for_conflicting_import ( & dest_import_resolution. value_target ,
2870
+ import_directive. span ,
2871
+ * ident,
2872
+ ValueNS ) ;
2873
+ dest_import_resolution. value_target = Some ( value_target. clone ( ) ) ;
2881
2874
}
2882
2875
}
2883
2876
match target_import_resolution. type_target {
2884
2877
None => {
2885
2878
// Continue.
2886
2879
}
2887
2880
Some ( ref type_target) => {
2888
- dest_import_resolution. type_target =
2889
- Some ( type_target. clone ( ) ) ;
2881
+ self . check_for_conflicting_import ( & dest_import_resolution. type_target ,
2882
+ import_directive. span ,
2883
+ * ident,
2884
+ TypeNS ) ;
2885
+ dest_import_resolution. type_target = Some ( type_target. clone ( ) ) ;
2890
2886
}
2891
2887
}
2892
2888
dest_import_resolution. is_public = is_public;
@@ -2908,8 +2904,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2908
2904
// Add all children from the containing module.
2909
2905
self . populate_module_if_necessary ( & containing_module) ;
2910
2906
2911
- for ( & name, name_bindings) in containing_module. children
2912
- . borrow ( ) . iter ( ) {
2907
+ for ( & name, name_bindings) in containing_module. children . borrow ( ) . iter ( ) {
2913
2908
self . merge_import_resolution ( module_,
2914
2909
containing_module. clone ( ) ,
2915
2910
import_directive,
@@ -2919,8 +2914,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2919
2914
}
2920
2915
2921
2916
// Add external module children from the containing module.
2922
- for ( & name, module) in containing_module. external_module_children
2923
- . borrow ( ) . iter ( ) {
2917
+ for ( & name, module) in containing_module. external_module_children . borrow ( ) . iter ( ) {
2924
2918
let name_bindings =
2925
2919
Rc :: new ( Resolver :: create_name_bindings_from_module ( module. clone ( ) ) ) ;
2926
2920
self . merge_import_resolution ( module_,
@@ -2965,41 +2959,39 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2965
2959
2966
2960
debug ! ( "(resolving glob import) writing resolution `{}` in `{}` \
2967
2961
to `{}`",
2968
- token:: get_name( name) . get( ) . to_string ( ) ,
2962
+ token:: get_name( name) . get( ) ,
2969
2963
self . module_to_string( & * containing_module) ,
2970
2964
self . module_to_string( module_) ) ;
2971
2965
2972
2966
// Merge the child item into the import resolution.
2973
- if name_bindings. defined_in_namespace_with ( ValueNS , IMPORTABLE | PUBLIC ) {
2974
- debug ! ( "(resolving glob import) ... for value target" ) ;
2975
- if dest_import_resolution. shadowable ( ValueNS ) == Shadowable :: Never {
2976
- let msg = format ! ( "a value named `{}` has already been imported \
2977
- in this module",
2978
- token:: get_name( name) . get( ) ) ;
2979
- self . session . span_err ( import_directive. span , msg. as_slice ( ) ) ;
2980
- } else {
2981
- dest_import_resolution. value_target =
2982
- Some ( Target :: new ( containing_module. clone ( ) ,
2983
- name_bindings. clone ( ) ,
2984
- import_directive. shadowable ) ) ;
2985
- dest_import_resolution. value_id = id;
2986
- }
2987
- }
2988
- if name_bindings. defined_in_namespace_with ( TypeNS , IMPORTABLE | PUBLIC ) {
2989
- debug ! ( "(resolving glob import) ... for type target" ) ;
2990
- if dest_import_resolution. shadowable ( TypeNS ) == Shadowable :: Never {
2991
- let msg = format ! ( "a type named `{}` has already been imported \
2992
- in this module",
2993
- token:: get_name( name) . get( ) ) ;
2994
- self . session . span_err ( import_directive. span , msg. as_slice ( ) ) ;
2995
- } else {
2996
- dest_import_resolution. type_target =
2997
- Some ( Target :: new ( containing_module,
2998
- name_bindings. clone ( ) ,
2999
- import_directive. shadowable ) ) ;
3000
- dest_import_resolution. type_id = id;
3001
- }
2967
+ {
2968
+ let merge_child_item = |namespace| {
2969
+ if name_bindings. defined_in_namespace_with ( namespace, IMPORTABLE | PUBLIC ) {
2970
+ let namespace_name = match namespace {
2971
+ TypeNS => "type" ,
2972
+ ValueNS => "value" ,
2973
+ } ;
2974
+ debug ! ( "(resolving glob import) ... for {} target" , namespace_name) ;
2975
+ if dest_import_resolution. shadowable ( namespace) == Shadowable :: Never {
2976
+ let msg = format ! ( "a {} named `{}` has already been imported \
2977
+ in this module",
2978
+ namespace_name,
2979
+ token:: get_name( name) . get( ) ) ;
2980
+ self . session . span_err ( import_directive. span , msg. as_slice ( ) ) ;
2981
+ } else {
2982
+ let target = Target :: new ( containing_module. clone ( ) ,
2983
+ name_bindings. clone ( ) ,
2984
+ import_directive. shadowable ) ;
2985
+ dest_import_resolution. set_target_and_id ( namespace,
2986
+ Some ( target) ,
2987
+ id) ;
2988
+ }
2989
+ }
2990
+ } ;
2991
+ merge_child_item ( ValueNS ) ;
2992
+ merge_child_item ( TypeNS ) ;
3002
2993
}
2994
+
3003
2995
dest_import_resolution. is_public = is_public;
3004
2996
3005
2997
self . check_for_conflicts_between_imports_and_items (
@@ -3019,6 +3011,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3019
3011
return
3020
3012
}
3021
3013
3014
+ debug ! ( "check_for_conflicting_import: {}; target exists: {}" ,
3015
+ token:: get_name( name) . get( ) ,
3016
+ target. is_some( ) ) ;
3017
+
3022
3018
match * target {
3023
3019
Some ( ref target) if target. shadowable != Shadowable :: Always => {
3024
3020
let msg = format ! ( "a {} named `{}` has already been imported \
0 commit comments