@@ -42,7 +42,6 @@ use self::ModulePrefixResult::*;
42
42
use self :: AssocItemResolveResult :: * ;
43
43
use self :: BareIdentifierPatternResolution :: * ;
44
44
use self :: ParentLink :: * ;
45
- use self :: FallbackChecks :: * ;
46
45
47
46
use rustc:: dep_graph:: DepNode ;
48
47
use rustc:: hir:: map as hir_map;
@@ -81,7 +80,7 @@ use rustc::hir::{Pat, PatKind, Path, PrimTy};
81
80
use rustc:: hir:: { PathSegment , PathParameters } ;
82
81
use rustc:: hir:: HirVec ;
83
82
use rustc:: hir:: { TraitRef , Ty , TyBool , TyChar , TyFloat , TyInt } ;
84
- use rustc:: hir:: { TyRptr , TyStr , TyUint , TyPath , TyPtr } ;
83
+ use rustc:: hir:: { TyRptr , TyStr , TyUint , TyPath } ;
85
84
86
85
use std:: collections:: { HashMap , HashSet } ;
87
86
use std:: cell:: { Cell , RefCell } ;
@@ -676,9 +675,7 @@ impl<T> ResolveResult<T> {
676
675
enum FallbackSuggestion {
677
676
NoSuggestion ,
678
677
Field ,
679
- Method ,
680
678
TraitItem ,
681
- StaticMethod ( String ) ,
682
679
TraitMethod ( String ) ,
683
680
}
684
681
@@ -1124,12 +1121,6 @@ impl<'a> ResolverArenas<'a> {
1124
1121
}
1125
1122
}
1126
1123
1127
- #[ derive( PartialEq ) ]
1128
- enum FallbackChecks {
1129
- Everything ,
1130
- OnlyTraitAndStatics ,
1131
- }
1132
-
1133
1124
impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
1134
1125
fn new ( session : & ' a Session ,
1135
1126
ast_map : & ' a hir_map:: Map < ' tcx > ,
@@ -2821,37 +2812,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2821
2812
}
2822
2813
2823
2814
fn find_fallback_in_self_type ( & mut self , name : Name ) -> FallbackSuggestion {
2824
- fn extract_path_and_node_id ( t : & Ty ,
2825
- allow : FallbackChecks )
2826
- -> Option < ( Path , NodeId , FallbackChecks ) > {
2815
+ fn extract_node_id ( t : & Ty ) -> Option < NodeId > {
2827
2816
match t. node {
2828
- TyPath ( None , ref path) => Some ( ( path. clone ( ) , t. id , allow) ) ,
2829
- TyPtr ( ref mut_ty) => extract_path_and_node_id ( & mut_ty. ty , OnlyTraitAndStatics ) ,
2830
- TyRptr ( _, ref mut_ty) => extract_path_and_node_id ( & mut_ty. ty , allow) ,
2817
+ TyPath ( None , _) => Some ( t. id ) ,
2818
+ TyRptr ( _, ref mut_ty) => extract_node_id ( & mut_ty. ty ) ,
2831
2819
// This doesn't handle the remaining `Ty` variants as they are not
2832
2820
// that commonly the self_type, it might be interesting to provide
2833
2821
// support for those in future.
2834
2822
_ => None ,
2835
2823
}
2836
2824
}
2837
2825
2838
- fn get_module < ' a , ' tcx > ( this : & mut Resolver < ' a , ' tcx > ,
2839
- span : Span ,
2840
- name_path : & [ ast:: Name ] )
2841
- -> Option < Module < ' a > > {
2842
- let last_name = name_path. last ( ) . unwrap ( ) ;
2843
-
2844
- if name_path. len ( ) == 1 {
2845
- match this. primitive_type_table . primitive_types . get ( last_name) {
2846
- Some ( _) => None ,
2847
- None => this. current_module . resolve_name_in_lexical_scope ( * last_name, TypeNS )
2848
- . and_then ( NameBinding :: module)
2849
- }
2850
- } else {
2851
- this. resolve_module_path ( & name_path, UseLexicalScope , span) . success ( )
2852
- }
2853
- }
2854
-
2855
2826
fn is_static_method ( this : & Resolver , did : DefId ) -> bool {
2856
2827
if let Some ( node_id) = this. ast_map . as_local_node_id ( did) {
2857
2828
let sig = match this. ast_map . get ( node_id) {
@@ -2871,15 +2842,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2871
2842
}
2872
2843
}
2873
2844
2874
- let ( path, node_id, allowed) = match self . current_self_type {
2875
- Some ( ref ty) => match extract_path_and_node_id ( ty, Everything ) {
2876
- Some ( x) => x,
2877
- None => return NoSuggestion ,
2878
- } ,
2879
- None => return NoSuggestion ,
2880
- } ;
2881
-
2882
- if allowed == Everything {
2845
+ if let Some ( node_id) = self . current_self_type . as_ref ( ) . and_then ( extract_node_id) {
2883
2846
// Look for a field with the same name in the current self_type.
2884
2847
match self . def_map . borrow ( ) . get ( & node_id) . map ( |d| d. full_def ( ) ) {
2885
2848
Some ( Def :: Enum ( did) ) |
@@ -2897,24 +2860,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2897
2860
}
2898
2861
}
2899
2862
2900
- let name_path = path. segments . iter ( ) . map ( |seg| seg. identifier . name ) . collect :: < Vec < _ > > ( ) ;
2901
-
2902
- // Look for a method in the current self type's impl module.
2903
- if let Some ( module) = get_module ( self , path. span , & name_path) {
2904
- if let Some ( binding) = module. resolve_name_in_lexical_scope ( name, ValueNS ) {
2905
- if let Some ( Def :: Method ( did) ) = binding. def ( ) {
2906
- if is_static_method ( self , did) {
2907
- return StaticMethod ( path_names_to_string ( & path, 0 ) ) ;
2908
- }
2909
- if self . current_trait_ref . is_some ( ) {
2910
- return TraitItem ;
2911
- } else if allowed == Everything {
2912
- return Method ;
2913
- }
2914
- }
2915
- }
2916
- }
2917
-
2918
2863
// Look for a method in the current trait.
2919
2864
if let Some ( ( trait_did, ref trait_ref) ) = self . current_trait_ref {
2920
2865
if let Some ( & did) = self . trait_item_map . get ( & ( name, trait_did) ) {
@@ -3073,10 +3018,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3073
3018
}
3074
3019
}
3075
3020
Field => format ! ( "`self.{}`" , path_name) ,
3076
- Method |
3077
3021
TraitItem => format ! ( "to call `self.{}`" , path_name) ,
3078
- TraitMethod ( path_str) |
3079
- StaticMethod ( path_str) =>
3022
+ TraitMethod ( path_str) =>
3080
3023
format ! ( "to call `{}::{}`" , path_str, path_name) ,
3081
3024
} ;
3082
3025
0 commit comments