@@ -42,7 +42,6 @@ use self::ModulePrefixResult::*;
4242use self :: AssocItemResolveResult :: * ;
4343use self :: BareIdentifierPatternResolution :: * ;
4444use self :: ParentLink :: * ;
45- use self :: FallbackChecks :: * ;
4645
4746use rustc:: dep_graph:: DepNode ;
4847use rustc:: hir:: map as hir_map;
@@ -81,7 +80,7 @@ use rustc::hir::{Pat, PatKind, Path, PrimTy};
8180use rustc:: hir:: { PathSegment , PathParameters } ;
8281use rustc:: hir:: HirVec ;
8382use 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 } ;
8584
8685use std:: collections:: { HashMap , HashSet } ;
8786use std:: cell:: { Cell , RefCell } ;
@@ -676,9 +675,7 @@ impl<T> ResolveResult<T> {
676675enum FallbackSuggestion {
677676 NoSuggestion ,
678677 Field ,
679- Method ,
680678 TraitItem ,
681- StaticMethod ( String ) ,
682679 TraitMethod ( String ) ,
683680}
684681
@@ -1124,12 +1121,6 @@ impl<'a> ResolverArenas<'a> {
11241121 }
11251122}
11261123
1127- #[ derive( PartialEq ) ]
1128- enum FallbackChecks {
1129- Everything ,
1130- OnlyTraitAndStatics ,
1131- }
1132-
11331124impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
11341125 fn new ( session : & ' a Session ,
11351126 ast_map : & ' a hir_map:: Map < ' tcx > ,
@@ -2821,37 +2812,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28212812 }
28222813
28232814 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 > {
28272816 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 ) ,
28312819 // This doesn't handle the remaining `Ty` variants as they are not
28322820 // that commonly the self_type, it might be interesting to provide
28332821 // support for those in future.
28342822 _ => None ,
28352823 }
28362824 }
28372825
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-
28552826 fn is_static_method ( this : & Resolver , did : DefId ) -> bool {
28562827 if let Some ( node_id) = this. ast_map . as_local_node_id ( did) {
28572828 let sig = match this. ast_map . get ( node_id) {
@@ -2871,15 +2842,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28712842 }
28722843 }
28732844
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) {
28832846 // Look for a field with the same name in the current self_type.
28842847 match self . def_map . borrow ( ) . get ( & node_id) . map ( |d| d. full_def ( ) ) {
28852848 Some ( Def :: Enum ( did) ) |
@@ -2897,24 +2860,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28972860 }
28982861 }
28992862
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-
29182863 // Look for a method in the current trait.
29192864 if let Some ( ( trait_did, ref trait_ref) ) = self . current_trait_ref {
29202865 if let Some ( & did) = self . trait_item_map . get ( & ( name, trait_did) ) {
@@ -3073,10 +3018,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30733018 }
30743019 }
30753020 Field => format ! ( "`self.{}`" , path_name) ,
3076- Method |
30773021 TraitItem => format ! ( "to call `self.{}`" , path_name) ,
3078- TraitMethod ( path_str) |
3079- StaticMethod ( path_str) =>
3022+ TraitMethod ( path_str) =>
30803023 format ! ( "to call `{}::{}`" , path_str, path_name) ,
30813024 } ;
30823025
0 commit comments