@@ -104,6 +104,7 @@ use middle::typeck::rscope::{RegionError};
104
104
use middle:: typeck:: rscope:: { in_binding_rscope, region_scope, type_rscope} ;
105
105
use middle:: typeck:: rscope;
106
106
use middle:: typeck:: { isr_alist, lookup_def_ccx, method_map_entry} ;
107
+ use middle:: typeck:: { method_map, vtable_map} ;
107
108
use middle:: typeck:: { method_origin, method_self, method_trait, no_params} ;
108
109
use middle:: typeck:: { require_same_types} ;
109
110
use util:: common:: { block_query, indenter, loop_query} ;
@@ -160,9 +161,13 @@ pub struct SelfInfo {
160
161
pub struct inherited {
161
162
infcx : @mut infer:: InferCtxt ,
162
163
locals : HashMap < ast:: node_id , ty:: t > ,
164
+
165
+ // Temporary tables:
163
166
node_types : HashMap < ast:: node_id , ty:: t > ,
164
167
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 ,
166
171
}
167
172
168
173
pub enum FnKind {
@@ -220,7 +225,9 @@ pub fn blank_inherited(ccx: @mut CrateCtxt) -> @inherited {
220
225
locals : HashMap ( ) ,
221
226
node_types : oldmap:: HashMap ( ) ,
222
227
node_type_substs : oldmap:: HashMap ( ) ,
223
- adjustments : oldmap:: HashMap ( )
228
+ adjustments : oldmap:: HashMap ( ) ,
229
+ method_map : oldmap:: HashMap ( ) ,
230
+ vtable_map : oldmap:: HashMap ( ) ,
224
231
}
225
232
}
226
233
@@ -1321,13 +1328,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1321
1328
sugar: ast:: CallSugar ) {
1322
1329
// Index expressions need to be handled separately, to inform them
1323
1330
// 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) ;
1331
1332
check_call_or_method( fcx,
1332
1333
sp,
1333
1334
call_expr_id,
@@ -1363,7 +1364,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1363
1364
CheckTraitsAndInherentMethods ,
1364
1365
AutoderefReceiver ) {
1365
1366
Some ( ref entry) => {
1366
- let method_map = fcx. ccx . method_map ;
1367
+ let method_map = fcx. inh . method_map ;
1367
1368
method_map. insert ( expr. id , ( * entry) ) ;
1368
1369
}
1369
1370
None => {
@@ -1435,7 +1436,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1435
1436
deref_args, CheckTraitsOnly , autoderef_receiver) {
1436
1437
Some ( ref origin) => {
1437
1438
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 ;
1439
1440
method_map. insert ( op_ex. id , * origin) ;
1440
1441
check_call_inner ( fcx, op_ex. span ,
1441
1442
op_ex. id , method_ty,
@@ -1689,7 +1690,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1689
1690
// Check field access expressions
1690
1691
fn check_field( fcx: @mut FnCtxt ,
1691
1692
expr: @ast:: expr,
1692
- is_callee: bool ,
1693
1693
base: @ast:: expr,
1694
1694
field: ast:: ident,
1695
1695
tys: & [ @ast:: Ty ] ) {
@@ -1723,7 +1723,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1723
1723
}
1724
1724
1725
1725
let tps = vec:: map( tys, |ty| fcx. to_ty( * ty) ) ;
1726
-
1727
1726
match method:: lookup( fcx,
1728
1727
expr,
1729
1728
base,
@@ -1734,34 +1733,30 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1734
1733
DontDerefArgs ,
1735
1734
CheckTraitsAndInherentMethods ,
1736
1735
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 ) ;
1751
1745
}
1746
+
1752
1747
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 ) ;
1762
1756
}
1763
1757
}
1764
1758
1759
+ fcx. write_error( expr. id) ;
1765
1760
}
1766
1761
1767
1762
fn check_struct_or_variant_fields( fcx: @mut FnCtxt ,
@@ -2750,15 +2745,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
2750
2745
}
2751
2746
}
2752
2747
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) ;
2762
2749
}
2763
2750
ast:: expr_index ( base, idx) => {
2764
2751
check_expr ( fcx, base) ;
0 commit comments