@@ -162,9 +162,12 @@ impl NamespaceResult {
162
162
}
163
163
164
164
enum NameDefinition {
165
- NoNameDefinition , //< The name was unbound.
166
- ChildNameDefinition ( Def , LastPrivate ) , //< The name identifies an immediate child.
167
- ImportNameDefinition ( Def , LastPrivate ) //< The name identifies an import.
165
+ // The name was unbound.
166
+ NoNameDefinition ,
167
+ // The name identifies an immediate child.
168
+ ChildNameDefinition ( Def , LastPrivate ) ,
169
+ // The name identifies an import.
170
+ ImportNameDefinition ( Def , LastPrivate ) ,
168
171
}
169
172
170
173
impl < ' a , ' v , ' tcx > Visitor < ' v > for Resolver < ' a , ' tcx > {
@@ -795,11 +798,6 @@ pub struct Resolver<'a, 'tcx:'a> {
795
798
// The current self type if inside an impl (used for better errors).
796
799
current_self_type : Option < Ty > ,
797
800
798
- // The ident for the keyword "self".
799
- self_name : Name ,
800
- // The ident for the non-keyword "Self".
801
- type_self_name : Name ,
802
-
803
801
// The idents for the primitive types.
804
802
primitive_type_table : PrimitiveTypeTable ,
805
803
@@ -869,9 +867,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
869
867
current_trait_ref : None ,
870
868
current_self_type : None ,
871
869
872
- self_name : special_names:: self_,
873
- type_self_name : special_names:: type_self,
874
-
875
870
primitive_type_table : PrimitiveTypeTable :: new ( ) ,
876
871
877
872
def_map : RefCell :: new ( NodeMap ( ) ) ,
@@ -1822,7 +1817,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1822
1817
let mut self_type_rib = Rib :: new ( ItemRibKind ) ;
1823
1818
1824
1819
// plain insert (no renaming, types are not currently hygienic....)
1825
- let name = self . type_self_name ;
1820
+ let name = special_names :: type_self ;
1826
1821
self_type_rib. bindings . insert ( name, DlDef ( DefSelfTy ( item. id ) ) ) ;
1827
1822
self . type_ribs . push ( self_type_rib) ;
1828
1823
@@ -2047,8 +2042,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2047
2042
2048
2043
fn with_optional_trait_ref < T , F > ( & mut self ,
2049
2044
opt_trait_ref : Option < & TraitRef > ,
2050
- f : F ) -> T where
2051
- F : FnOnce ( & mut Resolver ) -> T ,
2045
+ f : F )
2046
+ -> T
2047
+ where F : FnOnce ( & mut Resolver ) -> T ,
2052
2048
{
2053
2049
let mut new_val = None ;
2054
2050
if let Some ( trait_ref) = opt_trait_ref {
@@ -2585,11 +2581,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2585
2581
let span = path. span ;
2586
2582
let segments = & path. segments [ ..path. segments . len ( ) -path_depth] ;
2587
2583
2588
- let mk_res = |( def, lp) | PathResolution {
2589
- base_def : def,
2590
- last_private : lp,
2591
- depth : path_depth
2592
- } ;
2584
+ let mk_res = |( def, lp) | PathResolution :: new ( def, lp, path_depth) ;
2593
2585
2594
2586
if path. global {
2595
2587
let def = self . resolve_crate_relative_path ( span, segments, namespace) ;
@@ -2603,25 +2595,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2603
2595
check_ribs,
2604
2596
span) ;
2605
2597
2606
- if segments. len ( ) > 1 {
2607
- let def = self . resolve_module_relative_path ( span, segments, namespace) ;
2608
- match ( def, unqualified_def) {
2609
- ( Some ( ( ref d, _) ) , Some ( ( ref ud, _) ) ) if * d == * ud => {
2610
- self . session
2611
- . add_lint ( lint:: builtin:: UNUSED_QUALIFICATIONS ,
2612
- id, span,
2613
- "unnecessary qualification" . to_string ( ) ) ;
2614
- }
2615
- _ => ( )
2616
- }
2598
+ if segments. len ( ) <= 1 {
2599
+ return unqualified_def. map ( mk_res) ;
2600
+ }
2617
2601
2618
- def. map ( mk_res)
2619
- } else {
2620
- unqualified_def. map ( mk_res)
2602
+ let def = self . resolve_module_relative_path ( span, segments, namespace) ;
2603
+ match ( def, unqualified_def) {
2604
+ ( Some ( ( ref d, _) ) , Some ( ( ref ud, _) ) ) if * d == * ud => {
2605
+ self . session
2606
+ . add_lint ( lint:: builtin:: UNUSED_QUALIFICATIONS ,
2607
+ id, span,
2608
+ "unnecessary qualification" . to_string ( ) ) ;
2609
+ }
2610
+ _ => { }
2621
2611
}
2612
+
2613
+ def. map ( mk_res)
2622
2614
}
2623
2615
2624
- // resolve a single identifier (used as a varref)
2616
+ // Resolve a single identifier.
2625
2617
fn resolve_identifier ( & mut self ,
2626
2618
identifier : Ident ,
2627
2619
namespace : Namespace ,
@@ -2662,8 +2654,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2662
2654
match child_name_bindings. def_for_namespace ( namespace) {
2663
2655
Some ( def) => {
2664
2656
// Found it. Stop the search here.
2665
- let p = child_name_bindings. defined_in_public_namespace (
2666
- namespace) ;
2657
+ let p = child_name_bindings. defined_in_public_namespace ( namespace) ;
2667
2658
let lp = if p { LastMod ( AllPublic ) } else {
2668
2659
LastMod ( DependsOn ( def. def_id ( ) ) )
2669
2660
} ;
@@ -2734,8 +2725,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2734
2725
2735
2726
let containing_module;
2736
2727
let last_private;
2737
- let module = self . current_module . clone ( ) ;
2738
- match self . resolve_module_path ( module ,
2728
+ let current_module = self . current_module . clone ( ) ;
2729
+ match self . resolve_module_path ( current_module ,
2739
2730
& module_path[ ..] ,
2740
2731
UseLexicalScope ,
2741
2732
span,
@@ -2858,8 +2849,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2858
2849
2859
2850
match search_result {
2860
2851
Some ( DlDef ( def) ) => {
2861
- debug ! ( "(resolving path in local ribs) resolved `{}` to \
2862
- local: {:?}",
2852
+ debug ! ( "(resolving path in local ribs) resolved `{}` to local: {:?}" ,
2863
2853
token:: get_ident( ident) ,
2864
2854
def) ;
2865
2855
Some ( def)
@@ -2904,15 +2894,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2904
2894
panic ! ( "unexpected indeterminate result" ) ;
2905
2895
}
2906
2896
Failed ( err) => {
2907
- match err {
2908
- Some ( ( span, msg) ) =>
2909
- self . resolve_error ( span, & format ! ( "failed to resolve. {}" ,
2910
- msg) ) ,
2911
- None => ( )
2912
- }
2913
-
2914
2897
debug ! ( "(resolving item path by identifier in lexical scope) \
2915
2898
failed to resolve {}", token:: get_name( name) ) ;
2899
+
2900
+ if let Some ( ( span, msg) ) = err {
2901
+ self . resolve_error ( span, & format ! ( "failed to resolve. {}" , msg) )
2902
+ }
2903
+
2916
2904
return None ;
2917
2905
}
2918
2906
}
@@ -2964,10 +2952,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2964
2952
}
2965
2953
} else {
2966
2954
match this. resolve_module_path ( root,
2967
- & name_path[ ..] ,
2968
- UseLexicalScope ,
2969
- span,
2970
- PathSearch ) {
2955
+ & name_path[ ..] ,
2956
+ UseLexicalScope ,
2957
+ span,
2958
+ PathSearch ) {
2971
2959
Success ( ( module, _) ) => Some ( module) ,
2972
2960
_ => None
2973
2961
}
@@ -3203,8 +3191,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3203
3191
false // Stop advancing
3204
3192
} ) ;
3205
3193
3206
- if method_scope && & token :: get_name ( self . self_name ) [ .. ]
3207
- == path_name {
3194
+ if method_scope &&
3195
+ & token :: get_name ( special_names :: self_ ) [ .. ] == path_name {
3208
3196
self . resolve_error (
3209
3197
expr. span ,
3210
3198
"`self` is not available \
0 commit comments