@@ -2239,6 +2239,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22392239
22402240 obligations. map_move ( |o| self . register_predicate ( o) ) ;
22412241 }
2242+
2243+ // Only for fields! Returns <none> for methods>
2244+ // Indifferent to privacy flags
2245+ pub fn lookup_field_ty ( & self ,
2246+ span : Span ,
2247+ class_id : ast:: DefId ,
2248+ items : & [ ty:: field_ty ] ,
2249+ fieldname : ast:: Name ,
2250+ substs : & subst:: Substs < ' tcx > )
2251+ -> Option < Ty < ' tcx > >
2252+ {
2253+ let o_field = items. iter ( ) . find ( |f| f. name == fieldname) ;
2254+ o_field. map ( |f| ty:: lookup_field_type ( self . tcx ( ) , class_id, f. id , substs) )
2255+ . map ( |t| self . normalize_associated_types_in ( span, & t) )
2256+ }
2257+
2258+ pub fn lookup_tup_field_ty ( & self ,
2259+ span : Span ,
2260+ class_id : ast:: DefId ,
2261+ items : & [ ty:: field_ty ] ,
2262+ idx : uint ,
2263+ substs : & subst:: Substs < ' tcx > )
2264+ -> Option < Ty < ' tcx > >
2265+ {
2266+ let o_field = if idx < items. len ( ) { Some ( & items[ idx] ) } else { None } ;
2267+ o_field. map ( |f| ty:: lookup_field_type ( self . tcx ( ) , class_id, f. id , substs) )
2268+ . map ( |t| self . normalize_associated_types_in ( span, & t) )
2269+ }
22422270}
22432271
22442272impl < ' a , ' tcx > RegionScope for FnCtxt < ' a , ' tcx > {
@@ -2953,30 +2981,6 @@ pub fn impl_self_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
29532981 TypeAndSubsts { substs : substs, ty : substd_ty }
29542982}
29552983
2956- // Only for fields! Returns <none> for methods>
2957- // Indifferent to privacy flags
2958- pub fn lookup_field_ty < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
2959- class_id : ast:: DefId ,
2960- items : & [ ty:: field_ty ] ,
2961- fieldname : ast:: Name ,
2962- substs : & subst:: Substs < ' tcx > )
2963- -> Option < Ty < ' tcx > > {
2964-
2965- let o_field = items. iter ( ) . find ( |f| f. name == fieldname) ;
2966- o_field. map ( |f| ty:: lookup_field_type ( tcx, class_id, f. id , substs) )
2967- }
2968-
2969- pub fn lookup_tup_field_ty < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
2970- class_id : ast:: DefId ,
2971- items : & [ ty:: field_ty ] ,
2972- idx : uint ,
2973- substs : & subst:: Substs < ' tcx > )
2974- -> Option < Ty < ' tcx > > {
2975-
2976- let o_field = if idx < items. len ( ) { Some ( & items[ idx] ) } else { None } ;
2977- o_field. map ( |f| ty:: lookup_field_type ( tcx, class_id, f. id , substs) )
2978- }
2979-
29802984// Controls whether the arguments are automatically referenced. This is useful
29812985// for overloaded binary and unary operators.
29822986#[ derive( Copy , PartialEq ) ]
@@ -3398,8 +3402,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
33983402 ty:: ty_struct( base_id, substs) => {
33993403 debug ! ( "struct named {}" , ppaux:: ty_to_string( tcx, base_t) ) ;
34003404 let fields = ty:: lookup_struct_fields ( tcx, base_id) ;
3401- lookup_field_ty ( tcx , base_id, & fields[ ] ,
3402- field. node . name , & ( * substs) )
3405+ fcx . lookup_field_ty ( expr . span , base_id, & fields[ ] ,
3406+ field. node . name , & ( * substs) )
34033407 }
34043408 _ => None
34053409 }
@@ -3461,8 +3465,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
34613465 if tuple_like {
34623466 debug ! ( "tuple struct named {}" , ppaux:: ty_to_string( tcx, base_t) ) ;
34633467 let fields = ty:: lookup_struct_fields ( tcx, base_id) ;
3464- lookup_tup_field_ty ( tcx , base_id, & fields[ ] ,
3465- idx. node , & ( * substs) )
3468+ fcx . lookup_tup_field_ty ( expr . span , base_id, & fields[ ] ,
3469+ idx. node , & ( * substs) )
34663470 } else {
34673471 None
34683472 }
0 commit comments