11
11
#![ allow( non_camel_case_types) ]
12
12
13
13
use driver:: session:: Session ;
14
+ use lint;
14
15
use metadata:: csearch;
15
16
use metadata:: decoder:: { DefLike , DlDef , DlField , DlImpl } ;
16
17
use middle:: def:: * ;
17
18
use middle:: lang_items:: LanguageItems ;
18
19
use middle:: pat_util:: pat_bindings;
19
20
use middle:: subst:: { ParamSpace , FnSpace , TypeSpace } ;
20
- use lint ;
21
+ use middle :: ty :: { ExplicitSelfCategory , StaticExplicitSelfCategory } ;
21
22
use util:: nodemap:: { NodeMap , DefIdSet , FnvHashMap } ;
22
23
23
24
use syntax:: ast:: * ;
@@ -287,6 +288,24 @@ enum ModulePrefixResult {
287
288
PrefixFound ( Rc < Module > , uint )
288
289
}
289
290
291
+ #[ deriving( Clone , Eq , PartialEq ) ]
292
+ enum MethodIsStaticFlag {
293
+ MethodIsNotStatic ,
294
+ MethodIsStatic ,
295
+ }
296
+
297
+ impl MethodIsStaticFlag {
298
+ fn from_explicit_self_category ( explicit_self_category :
299
+ ExplicitSelfCategory )
300
+ -> MethodIsStaticFlag {
301
+ if explicit_self_category == StaticExplicitSelfCategory {
302
+ MethodIsStatic
303
+ } else {
304
+ MethodIsNotStatic
305
+ }
306
+ }
307
+ }
308
+
290
309
#[ deriving( PartialEq ) ]
291
310
enum NameSearchType {
292
311
/// We're doing a name search in order to resolve a `use` directive.
@@ -805,7 +824,8 @@ struct Resolver<'a> {
805
824
806
825
graph_root : NameBindings ,
807
826
808
- method_map : RefCell < FnvHashMap < ( Name , DefId ) , ast:: ExplicitSelf_ > > ,
827
+ method_map : RefCell < FnvHashMap < ( Name , DefId ) , MethodIsStaticFlag > > ,
828
+
809
829
structs : FnvHashMap < DefId , Vec < Name > > ,
810
830
811
831
// The number of imports that are currently unresolved.
@@ -1361,17 +1381,19 @@ impl<'a> Resolver<'a> {
1361
1381
let ident = ty_m. ident ;
1362
1382
1363
1383
// Add it as a name in the trait module.
1364
- let def = match ty_m. explicit_self . node {
1384
+ let ( def, static_flag ) = match ty_m. explicit_self . node {
1365
1385
SelfStatic => {
1366
1386
// Static methods become `def_static_method`s.
1367
- DefStaticMethod ( local_def ( ty_m. id ) ,
1387
+ ( DefStaticMethod ( local_def ( ty_m. id ) ,
1368
1388
FromTrait ( local_def ( item. id ) ) ,
1369
- ty_m. fn_style )
1389
+ ty_m. fn_style ) ,
1390
+ MethodIsStatic )
1370
1391
}
1371
1392
_ => {
1372
1393
// Non-static methods become `def_method`s.
1373
- DefMethod ( local_def ( ty_m. id ) ,
1374
- Some ( local_def ( item. id ) ) )
1394
+ ( DefMethod ( local_def ( ty_m. id ) ,
1395
+ Some ( local_def ( item. id ) ) ) ,
1396
+ MethodIsNotStatic )
1375
1397
}
1376
1398
} ;
1377
1399
@@ -1382,8 +1404,9 @@ impl<'a> Resolver<'a> {
1382
1404
ty_m. span ) ;
1383
1405
method_name_bindings. define_value ( def, ty_m. span , true ) ;
1384
1406
1385
- self . method_map . borrow_mut ( ) . insert ( ( ident. name , def_id) ,
1386
- ty_m. explicit_self . node ) ;
1407
+ self . method_map
1408
+ . borrow_mut ( )
1409
+ . insert ( ( ident. name , def_id) , static_flag) ;
1387
1410
}
1388
1411
1389
1412
name_bindings. define_type ( DefTrait ( def_id) , sp, is_public) ;
@@ -1670,7 +1693,11 @@ impl<'a> Resolver<'a> {
1670
1693
trait method '{}'",
1671
1694
token:: get_ident( method_name) ) ;
1672
1695
1673
- self . method_map . borrow_mut ( ) . insert ( ( method_name. name , def_id) , explicit_self) ;
1696
+ self . method_map
1697
+ . borrow_mut ( )
1698
+ . insert ( ( method_name. name , def_id) ,
1699
+ MethodIsStaticFlag :: from_explicit_self_category (
1700
+ explicit_self) ) ;
1674
1701
1675
1702
if is_exported {
1676
1703
self . external_exports . insert ( method_def_id) ;
@@ -3678,6 +3705,13 @@ impl<'a> Resolver<'a> {
3678
3705
this. resolve_type ( & * argument. ty ) ;
3679
3706
}
3680
3707
3708
+ match ty_m. explicit_self . node {
3709
+ SelfExplicit ( ref typ, _) => {
3710
+ this. resolve_type ( * typ)
3711
+ }
3712
+ _ => { }
3713
+ }
3714
+
3681
3715
this. resolve_type ( & * ty_m. decl . output ) ;
3682
3716
} ) ;
3683
3717
}
@@ -4009,7 +4043,14 @@ impl<'a> Resolver<'a> {
4009
4043
method. id ,
4010
4044
rib_kind) ;
4011
4045
4012
- self . resolve_function ( rib_kind, Some ( method. pe_fn_decl ( ) ) , type_parameters,
4046
+ match method. pe_explicit_self ( ) . node {
4047
+ SelfExplicit ( ref typ, _) => self . resolve_type ( * typ) ,
4048
+ _ => { }
4049
+ }
4050
+
4051
+ self . resolve_function ( rib_kind,
4052
+ Some ( method. pe_fn_decl ( ) ) ,
4053
+ type_parameters,
4013
4054
method. pe_body ( ) ) ;
4014
4055
}
4015
4056
@@ -4765,7 +4806,7 @@ impl<'a> Resolver<'a> {
4765
4806
match containing_module. def_id . get ( ) {
4766
4807
Some ( def_id) => {
4767
4808
match self . method_map . borrow ( ) . find ( & ( ident. name , def_id) ) {
4768
- Some ( x ) if * x == SelfStatic => ( ) ,
4809
+ Some ( & MethodIsStatic ) => ( ) ,
4769
4810
None => ( ) ,
4770
4811
_ => {
4771
4812
debug ! ( "containing module was a trait or impl \
@@ -5037,7 +5078,7 @@ impl<'a> Resolver<'a> {
5037
5078
let path_str = self . path_idents_to_string ( & trait_ref. path ) ;
5038
5079
5039
5080
match method_map. find ( & ( name, did) ) {
5040
- Some ( & SelfStatic ) => return StaticTraitMethod ( path_str) ,
5081
+ Some ( & MethodIsStatic ) => return StaticTraitMethod ( path_str) ,
5041
5082
Some ( _) => return TraitMethod ,
5042
5083
None => { }
5043
5084
}
0 commit comments