@@ -16,10 +16,12 @@ use middle::def;
16
16
use middle:: privacy:: { AllPublic , DependsOn , LastPrivate , LastMod } ;
17
17
use middle:: subst;
18
18
use middle:: traits;
19
- use middle:: ty:: { self , AsPredicate , ToPolyTraitRef } ;
19
+ use middle:: ty:: * ;
20
+ use middle:: ty;
20
21
use middle:: infer;
21
22
use util:: ppaux:: Repr ;
22
23
24
+ use std:: rc:: Rc ;
23
25
use syntax:: ast:: DefId ;
24
26
use syntax:: ast;
25
27
use syntax:: codemap:: Span ;
@@ -37,7 +39,7 @@ pub enum MethodError {
37
39
// Did not find an applicable method, but we did find various
38
40
// static methods that may apply, as well as a list of
39
41
// not-in-scope traits which may work.
40
- NoMatch ( Vec < CandidateSource > , Vec < ast:: DefId > , probe :: Mode ) ,
42
+ NoMatch ( Vec < CandidateSource > , Vec < ast:: DefId > ) ,
41
43
42
44
// Multiple methods might apply.
43
45
Ambiguity ( Vec < CandidateSource > ) ,
@@ -60,7 +62,7 @@ type ItemIndex = usize; // just for doc purposes
60
62
pub fn exists < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
61
63
span : Span ,
62
64
method_name : ast:: Name ,
63
- self_ty : ty :: Ty < ' tcx > ,
65
+ self_ty : Ty < ' tcx > ,
64
66
call_expr_id : ast:: NodeId )
65
67
-> bool
66
68
{
@@ -90,11 +92,11 @@ pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
90
92
pub fn lookup < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
91
93
span : Span ,
92
94
method_name : ast:: Name ,
93
- self_ty : ty :: Ty < ' tcx > ,
94
- supplied_method_types : Vec < ty :: Ty < ' tcx > > ,
95
+ self_ty : Ty < ' tcx > ,
96
+ supplied_method_types : Vec < Ty < ' tcx > > ,
95
97
call_expr : & ' tcx ast:: Expr ,
96
98
self_expr : & ' tcx ast:: Expr )
97
- -> Result < ty :: MethodCallee < ' tcx > , MethodError >
99
+ -> Result < MethodCallee < ' tcx > , MethodError >
98
100
{
99
101
debug ! ( "lookup(method_name={}, self_ty={}, call_expr={}, self_expr={})" ,
100
102
method_name. repr( fcx. tcx( ) ) ,
@@ -113,9 +115,9 @@ pub fn lookup_in_trait<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
113
115
self_expr : Option < & ast:: Expr > ,
114
116
m_name : ast:: Name ,
115
117
trait_def_id : DefId ,
116
- self_ty : ty :: Ty < ' tcx > ,
117
- opt_input_types : Option < Vec < ty :: Ty < ' tcx > > > )
118
- -> Option < ty :: MethodCallee < ' tcx > >
118
+ self_ty : Ty < ' tcx > ,
119
+ opt_input_types : Option < Vec < Ty < ' tcx > > > )
120
+ -> Option < MethodCallee < ' tcx > >
119
121
{
120
122
lookup_in_trait_adjusted ( fcx, span, self_expr, m_name, trait_def_id,
121
123
0 , false , self_ty, opt_input_types)
@@ -137,9 +139,9 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
137
139
trait_def_id : DefId ,
138
140
autoderefs : usize ,
139
141
unsize : bool ,
140
- self_ty : ty :: Ty < ' tcx > ,
141
- opt_input_types : Option < Vec < ty :: Ty < ' tcx > > > )
142
- -> Option < ty :: MethodCallee < ' tcx > >
142
+ self_ty : Ty < ' tcx > ,
143
+ opt_input_types : Option < Vec < Ty < ' tcx > > > )
144
+ -> Option < MethodCallee < ' tcx > >
143
145
{
144
146
debug ! ( "lookup_in_trait_adjusted(self_ty={}, self_expr={}, m_name={}, trait_def_id={})" ,
145
147
self_ty. repr( fcx. tcx( ) ) ,
@@ -184,9 +186,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
184
186
// Trait must have a method named `m_name` and it should not have
185
187
// type parameters or early-bound regions.
186
188
let tcx = fcx. tcx ( ) ;
187
- let ( method_num, method_ty) = trait_item ( tcx, trait_def_id, m_name)
188
- . and_then ( |( idx, item) | item. as_opt_method ( ) . map ( |m| ( idx, m) ) )
189
- . unwrap ( ) ;
189
+ let ( method_num, method_ty) = trait_method ( tcx, trait_def_id, m_name) . unwrap ( ) ;
190
190
assert_eq ! ( method_ty. generics. types. len( subst:: FnSpace ) , 0 ) ;
191
191
assert_eq ! ( method_ty. generics. regions. len( subst:: FnSpace ) , 0 ) ;
192
192
@@ -288,10 +288,10 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
288
288
}
289
289
}
290
290
291
- let callee = ty :: MethodCallee {
292
- origin : ty :: MethodTypeParam ( ty :: MethodParam { trait_ref : trait_ref. clone ( ) ,
293
- method_num : method_num,
294
- impl_def_id : None } ) ,
291
+ let callee = MethodCallee {
292
+ origin : MethodTypeParam ( MethodParam { trait_ref : trait_ref. clone ( ) ,
293
+ method_num : method_num,
294
+ impl_def_id : None } ) ,
295
295
ty : fty,
296
296
substs : trait_ref. substs . clone ( )
297
297
} ;
@@ -304,7 +304,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
304
304
pub fn resolve_ufcs < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
305
305
span : Span ,
306
306
method_name : ast:: Name ,
307
- self_ty : ty :: Ty < ' tcx > ,
307
+ self_ty : Ty < ' tcx > ,
308
308
expr_id : ast:: NodeId )
309
309
-> Result < ( def:: Def , LastPrivate ) , MethodError >
310
310
{
@@ -322,40 +322,41 @@ pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
322
322
_ => def:: FromTrait ( pick. item . container ( ) . id ( ) )
323
323
} ;
324
324
let def_result = match pick. item {
325
- ty :: ImplOrTraitItem :: MethodTraitItem ( ..) => def:: DefMethod ( def_id, provenance) ,
326
- ty :: ImplOrTraitItem :: ConstTraitItem ( ..) => def:: DefAssociatedConst ( def_id, provenance) ,
327
- ty :: ImplOrTraitItem :: TypeTraitItem ( ..) => {
325
+ ImplOrTraitItem :: MethodTraitItem ( ..) => def:: DefMethod ( def_id, provenance) ,
326
+ ImplOrTraitItem :: ConstTraitItem ( ..) => def:: DefAssociatedConst ( def_id, provenance) ,
327
+ ImplOrTraitItem :: TypeTraitItem ( ..) => {
328
328
fcx. tcx ( ) . sess . span_bug ( span, "resolve_ufcs: probe picked associated type" ) ;
329
329
}
330
330
} ;
331
331
Ok ( ( def_result, lp) )
332
332
}
333
333
334
334
335
- /// Find item with name `item_name ` defined in `trait_def_id` and return it, along with its
336
- /// index (or `None`, if no such item ).
337
- fn trait_item < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
338
- trait_def_id : ast:: DefId ,
339
- item_name : ast:: Name )
340
- -> Option < ( usize , ty:: ImplOrTraitItem < ' tcx > ) >
335
+ /// Find method with name `method_name ` defined in `trait_def_id` and return it, along with its
336
+ /// index (or `None`, if no such method ).
337
+ fn trait_method < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
338
+ trait_def_id : ast:: DefId ,
339
+ method_name : ast:: Name )
340
+ -> Option < ( usize , Rc < ty:: Method < ' tcx > > ) >
341
341
{
342
342
let trait_items = ty:: trait_items ( tcx, trait_def_id) ;
343
343
trait_items
344
344
. iter ( )
345
345
. enumerate ( )
346
- . find ( |& ( _, ref item) | item. name ( ) == item_name )
347
- . map ( |( num , item) | ( num , ( * item) . clone ( ) ) )
346
+ . find ( |& ( _, ref item) | item. name ( ) == method_name )
347
+ . and_then ( |( idx , item) | item. as_opt_method ( ) . map ( |m| ( idx , m ) ) )
348
348
}
349
349
350
- fn impl_item < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
351
- impl_def_id : ast:: DefId ,
352
- item_name : ast:: Name )
353
- -> Option < ty:: ImplOrTraitItem < ' tcx > >
350
+ fn impl_method < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
351
+ impl_def_id : ast:: DefId ,
352
+ method_name : ast:: Name )
353
+ -> Option < Rc < ty:: Method < ' tcx > > >
354
354
{
355
355
let impl_items = tcx. impl_items . borrow ( ) ;
356
356
let impl_items = impl_items. get ( & impl_def_id) . unwrap ( ) ;
357
357
impl_items
358
358
. iter ( )
359
359
. map ( |& did| ty:: impl_or_trait_item ( tcx, did. def_id ( ) ) )
360
- . find ( |m| m. name ( ) == item_name)
360
+ . find ( |m| m. name ( ) == method_name)
361
+ . and_then ( |item| item. as_opt_method ( ) )
361
362
}
0 commit comments