@@ -104,6 +104,7 @@ use middle::typeck::rscope::{RegionError};
104104use middle:: typeck:: rscope:: { in_binding_rscope, region_scope, type_rscope} ;
105105use middle:: typeck:: rscope;
106106use middle:: typeck:: { isr_alist, lookup_def_ccx, method_map_entry} ;
107+ use middle:: typeck:: { method_map, vtable_map} ;
107108use middle:: typeck:: { method_origin, method_self, method_trait, no_params} ;
108109use middle:: typeck:: { require_same_types} ;
109110use util:: common:: { block_query, indenter, loop_query} ;
@@ -160,9 +161,13 @@ pub struct SelfInfo {
160161pub struct inherited {
161162 infcx : @mut infer:: InferCtxt ,
162163 locals : HashMap < ast:: node_id , ty:: t > ,
164+
165+ // Temporary tables:
163166 node_types : HashMap < ast:: node_id , ty:: t > ,
164167 node_type_substs : HashMap < ast:: node_id , ty:: substs > ,
165- adjustments : HashMap < ast:: node_id , @ty:: AutoAdjustment >
168+ adjustments : HashMap < ast:: node_id , @ty:: AutoAdjustment > ,
169+ method_map : method_map ,
170+ vtable_map : vtable_map ,
166171}
167172
168173pub enum FnKind {
@@ -220,7 +225,9 @@ pub fn blank_inherited(ccx: @mut CrateCtxt) -> @inherited {
220225 locals : HashMap ( ) ,
221226 node_types : oldmap:: HashMap ( ) ,
222227 node_type_substs : oldmap:: HashMap ( ) ,
223- adjustments : oldmap:: HashMap ( )
228+ adjustments : oldmap:: HashMap ( ) ,
229+ method_map : oldmap:: HashMap ( ) ,
230+ vtable_map : oldmap:: HashMap ( ) ,
224231 }
225232}
226233
@@ -1321,13 +1328,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13211328 sugar: ast:: CallSugar ) {
13221329 // Index expressions need to be handled separately, to inform them
13231330 // that they appear in call position.
1324- match f. node {
1325- ast:: expr_field( ref base, ref field, ref tys) => {
1326- check_field ( fcx, f, true , * base, * field, * tys)
1327- }
1328- _ => check_expr ( fcx, f)
1329- } ;
1330-
1331+ let mut bot = check_expr( fcx, f) ;
13311332 check_call_or_method( fcx,
13321333 sp,
13331334 call_expr_id,
@@ -1363,7 +1364,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13631364 CheckTraitsAndInherentMethods ,
13641365 AutoderefReceiver ) {
13651366 Some ( ref entry) => {
1366- let method_map = fcx. ccx . method_map ;
1367+ let method_map = fcx. inh . method_map ;
13671368 method_map. insert ( expr. id , ( * entry) ) ;
13681369 }
13691370 None => {
@@ -1435,7 +1436,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
14351436 deref_args, CheckTraitsOnly , autoderef_receiver) {
14361437 Some ( ref origin) => {
14371438 let method_ty = fcx. node_ty ( op_ex. callee_id ) ;
1438- let method_map = fcx. ccx . method_map ;
1439+ let method_map = fcx. inh . method_map ;
14391440 method_map. insert ( op_ex. id , * origin) ;
14401441 check_call_inner ( fcx, op_ex. span ,
14411442 op_ex. id , method_ty,
@@ -1689,7 +1690,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
16891690 // Check field access expressions
16901691 fn check_field( fcx: @mut FnCtxt ,
16911692 expr: @ast:: expr,
1692- is_callee: bool ,
16931693 base: @ast:: expr,
16941694 field: ast:: ident,
16951695 tys: & [ @ast:: Ty ] ) {
@@ -1723,7 +1723,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
17231723 }
17241724
17251725 let tps = vec:: map( tys, |ty| fcx. to_ty( * ty) ) ;
1726-
17271726 match method:: lookup( fcx,
17281727 expr,
17291728 base,
@@ -1734,34 +1733,30 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
17341733 DontDerefArgs ,
17351734 CheckTraitsAndInherentMethods ,
17361735 AutoderefReceiver ) {
1737- Some ( ref entry) => {
1738- let method_map = fcx. ccx. method_map;
1739- method_map. insert( expr. id, ( * entry) ) ;
1740-
1741- // If we have resolved to a method but this is not in
1742- // a callee position, error
1743- if !is_callee {
1744- tcx. sess. span_err(
1745- expr. span,
1746- ~"attempted to take value of method \
1747- ( try writing an anonymous function) ") ;
1748- // Add error type for the result
1749- fcx. write_error( expr. id) ;
1750- }
1736+ Some ( _) => {
1737+ fcx. type_error_message(
1738+ expr. span,
1739+ |actual| {
1740+ fmt ! ( "attempted to take value of method `%s` on type `%s` \
1741+ (try writing an anonymous function)",
1742+ * tcx. sess. str_of( field) , actual)
1743+ } ,
1744+ expr_t, None ) ;
17511745 }
1746+
17521747 None => {
1753- fcx. type_error_message( expr. span,
1754- |actual| {
1755- fmt ! ( "attempted access of field `%s` on type `%s`, but \
1756- no field or method with that name was found",
1757- * tcx. sess. str_of( field) , actual)
1758- } ,
1759- expr_t, None ) ;
1760- // Add error type for the result
1761- fcx. write_error( expr. id) ;
1748+ fcx. type_error_message(
1749+ expr. span,
1750+ |actual| {
1751+ fmt ! ( "attempted access of field `%s` on type `%s`, \
1752+ but no field with that name was found",
1753+ * tcx. sess. str_of( field) , actual)
1754+ } ,
1755+ expr_t, None ) ;
17621756 }
17631757 }
17641758
1759+ fcx. write_error( expr. id) ;
17651760 }
17661761
17671762 fn check_struct_or_variant_fields( fcx: @mut FnCtxt ,
@@ -2750,15 +2745,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
27502745 }
27512746 }
27522747 ast:: expr_field ( base, field, ref tys) => {
2753- check_field ( fcx, expr, false , base, field, * tys) ;
2754- let base_t = fcx. expr_ty ( base) ;
2755- if ty:: type_is_error ( base_t) {
2756- fcx. write_error ( id) ;
2757- }
2758- else if ty:: type_is_bot ( base_t) {
2759- fcx. write_bot ( id) ;
2760- }
2761- // Otherwise, type already got written
2748+ check_field ( fcx, expr, base, field, * tys) ;
27622749 }
27632750 ast:: expr_index ( base, idx) => {
27642751 check_expr ( fcx, base) ;
0 commit comments