Skip to content

Commit e11d13f

Browse files
committed
Rip out old code that still structured method calls as a
expr_call(expr_field(...)) rather than an expr_method_call. There is probably more such code in trans that should be removed.
1 parent d96bbb9 commit e11d13f

File tree

7 files changed

+114
-160
lines changed

7 files changed

+114
-160
lines changed

src/librustc/middle/typeck/check/mod.rs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,13 +1321,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13211321
sugar: ast::CallSugar) {
13221322
// Index expressions need to be handled separately, to inform them
13231323
// 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-
1324+
let mut bot = check_expr(fcx, f);
13311325
check_call_or_method(fcx,
13321326
sp,
13331327
call_expr_id,
@@ -1689,7 +1683,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
16891683
// Check field access expressions
16901684
fn check_field(fcx: @mut FnCtxt,
16911685
expr: @ast::expr,
1692-
is_callee: bool,
16931686
base: @ast::expr,
16941687
field: ast::ident,
16951688
tys: &[@ast::Ty]) {
@@ -1723,7 +1716,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
17231716
}
17241717

17251718
let tps = vec::map(tys, |ty| fcx.to_ty(*ty));
1726-
17271719
match method::lookup(fcx,
17281720
expr,
17291721
base,
@@ -1734,34 +1726,30 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
17341726
DontDerefArgs,
17351727
CheckTraitsAndInherentMethods,
17361728
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-
}
1729+
Some(_) => {
1730+
fcx.type_error_message(
1731+
expr.span,
1732+
|actual| {
1733+
fmt!("attempted to take value of method `%s` on type `%s` \
1734+
(try writing an anonymous function)",
1735+
*tcx.sess.str_of(field), actual)
1736+
},
1737+
expr_t, None);
17511738
}
1739+
17521740
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);
1741+
fcx.type_error_message(
1742+
expr.span,
1743+
|actual| {
1744+
fmt!("attempted access of field `%s` on type `%s`, \
1745+
but no field with that name was found",
1746+
*tcx.sess.str_of(field), actual)
1747+
},
1748+
expr_t, None);
17621749
}
17631750
}
17641751

1752+
fcx.write_error(expr.id);
17651753
}
17661754

17671755
fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
@@ -2750,15 +2738,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
27502738
}
27512739
}
27522740
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
2741+
check_field(fcx, expr, base, field, *tys);
27622742
}
27632743
ast::expr_index(base, idx) => {
27642744
check_expr(fcx, base);

src/libsyntax/ext/auto_encode.rs

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ priv impl @ext_ctxt {
416416
self.expr(span, ast::expr_call(expr, args, ast::NoSugar))
417417
}
418418

419+
fn expr_method_call(
420+
&self,
421+
span: span,
422+
expr: @ast::expr,
423+
ident: ast::ident,
424+
+args: ~[@ast::expr]
425+
) -> @ast::expr {
426+
self.expr(span, ast::expr_method_call(expr, ident, ~[], args, ast::NoSugar))
427+
}
428+
419429
fn lambda_expr(&self, expr: @ast::expr) -> @ast::expr {
420430
self.lambda(self.expr_blk(expr))
421431
}
@@ -712,30 +722,24 @@ fn mk_struct_ser_impl(
712722
let fields = do mk_struct_fields(fields).mapi |idx, field| {
713723
// ast for `|| self.$(name).encode(__s)`
714724
let expr_lambda = cx.lambda_expr(
715-
cx.expr_call(
725+
cx.expr_method_call(
716726
span,
717727
cx.expr_field(
718728
span,
719-
cx.expr_field(
720-
span,
721-
cx.expr_var(span, ~"self"),
722-
field.ident
723-
),
724-
cx.ident_of(~"encode")
729+
cx.expr_var(span, ~"self"),
730+
field.ident
725731
),
732+
cx.ident_of(~"encode"),
726733
~[cx.expr_var(span, ~"__s")]
727734
)
728735
);
729736

730737
// ast for `__s.emit_field($(name), $(idx), $(expr_lambda))`
731738
cx.stmt(
732-
cx.expr_call(
739+
cx.expr_method_call(
733740
span,
734-
cx.expr_field(
735-
span,
736-
cx.expr_var(span, ~"__s"),
737-
cx.ident_of(~"emit_field")
738-
),
741+
cx.expr_var(span, ~"__s"),
742+
cx.ident_of(~"emit_field"),
739743
~[
740744
cx.lit_str(span, @cx.str_of(field.ident)),
741745
cx.lit_uint(span, idx),
@@ -746,13 +750,10 @@ fn mk_struct_ser_impl(
746750
};
747751

748752
// ast for `__s.emit_struct($(name), || $(fields))`
749-
let ser_body = cx.expr_call(
753+
let ser_body = cx.expr_method_call(
750754
span,
751-
cx.expr_field(
752-
span,
753-
cx.expr_var(span, ~"__s"),
754-
cx.ident_of(~"emit_struct")
755-
),
755+
cx.expr_var(span, ~"__s"),
756+
cx.ident_of(~"emit_struct"),
756757
~[
757758
cx.lit_str(span, @cx.str_of(ident)),
758759
cx.lit_uint(span, vec::len(fields)),
@@ -788,13 +789,10 @@ fn mk_struct_deser_impl(
788789
);
789790

790791
// ast for `__d.read_field($(name), $(idx), $(expr_lambda))`
791-
let expr: @ast::expr = cx.expr_call(
792+
let expr: @ast::expr = cx.expr_method_call(
792793
span,
793-
cx.expr_field(
794-
span,
795-
cx.expr_var(span, ~"__d"),
796-
cx.ident_of(~"read_field")
797-
),
794+
cx.expr_var(span, ~"__d"),
795+
cx.ident_of(~"read_field"),
798796
~[
799797
cx.lit_str(span, @cx.str_of(field.ident)),
800798
cx.lit_uint(span, idx),
@@ -813,13 +811,10 @@ fn mk_struct_deser_impl(
813811
};
814812

815813
// ast for `read_struct($(name), || $(fields))`
816-
let body = cx.expr_call(
814+
let body = cx.expr_method_call(
817815
span,
818-
cx.expr_field(
819-
span,
820-
cx.expr_var(span, ~"__d"),
821-
cx.ident_of(~"read_struct")
822-
),
816+
cx.expr_var(span, ~"__d"),
817+
cx.ident_of(~"read_struct"),
823818
~[
824819
cx.lit_str(span, @cx.str_of(ident)),
825820
cx.lit_uint(span, vec::len(fields)),
@@ -943,13 +938,10 @@ fn ser_variant(
943938
944939
// ast for `|| $(v).encode(__s)`
945940
let expr_encode = cx.lambda_expr(
946-
cx.expr_call(
941+
cx.expr_method_call(
947942
span,
948-
cx.expr_field(
949-
span,
950-
cx.expr_path(span, ~[names[a_idx]]),
951-
cx.ident_of(~"encode")
952-
),
943+
cx.expr_path(span, ~[names[a_idx]]),
944+
cx.ident_of(~"encode"),
953945
~[cx.expr_var(span, ~"__s")]
954946
)
955947
);
@@ -965,13 +957,10 @@ fn ser_variant(
965957
};
966958
967959
// ast for `__s.emit_enum_variant($(name), $(idx), $(sz), $(lambda))`
968-
let body = cx.expr_call(
960+
let body = cx.expr_method_call(
969961
span,
970-
cx.expr_field(
971-
span,
972-
cx.expr_var(span, ~"__s"),
973-
cx.ident_of(~"emit_enum_variant")
974-
),
962+
cx.expr_var(span, ~"__s"),
963+
cx.ident_of(~"emit_enum_variant"),
975964
~[
976965
cx.lit_str(span, @cx.str_of(v_name)),
977966
cx.lit_uint(span, v_idx),
@@ -1019,13 +1008,10 @@ fn mk_enum_ser_body(
10191008
);
10201009
10211010
// ast for `__s.emit_enum($(name), || $(match_expr))`
1022-
cx.expr_call(
1011+
cx.expr_method_call(
10231012
span,
1024-
cx.expr_field(
1025-
span,
1026-
cx.expr_var(span, ~"__s"),
1027-
cx.ident_of(~"emit_enum")
1028-
),
1013+
cx.expr_var(span, ~"__s"),
1014+
cx.ident_of(~"emit_enum"),
10291015
~[
10301016
cx.lit_str(span, @cx.str_of(name)),
10311017
cx.lambda_expr(match_expr),
@@ -1055,13 +1041,10 @@ fn mk_enum_deser_variant_nary(
10551041
);
10561042
10571043
// ast for `__d.read_enum_variant_arg($(a_idx), $(expr_lambda))`
1058-
cx.expr_call(
1044+
cx.expr_method_call(
10591045
span,
1060-
cx.expr_field(
1061-
span,
1062-
cx.expr_var(span, ~"__d"),
1063-
cx.ident_of(~"read_enum_variant_arg")
1064-
),
1046+
cx.expr_var(span, ~"__d"),
1047+
cx.ident_of(~"read_enum_variant_arg"),
10651048
~[cx.lit_uint(span, idx), expr_lambda]
10661049
)
10671050
};
@@ -1171,25 +1154,19 @@ fn mk_enum_deser_body(
11711154
11721155
// ast for `__d.read_enum_variant($(expr_lambda))`
11731156
let expr_lambda = ext_cx.lambda_expr(
1174-
ext_cx.expr_call(
1157+
ext_cx.expr_method_call(
11751158
span,
1176-
ext_cx.expr_field(
1177-
span,
1178-
ext_cx.expr_var(span, ~"__d"),
1179-
ext_cx.ident_of(~"read_enum_variant")
1180-
),
1159+
ext_cx.expr_var(span, ~"__d"),
1160+
ext_cx.ident_of(~"read_enum_variant"),
11811161
~[expr_lambda]
11821162
)
11831163
);
11841164
11851165
// ast for `__d.read_enum($(e_name), $(expr_lambda))`
1186-
ext_cx.expr_call(
1166+
ext_cx.expr_method_call(
11871167
span,
1188-
ext_cx.expr_field(
1189-
span,
1190-
ext_cx.expr_var(span, ~"__d"),
1191-
ext_cx.ident_of(~"read_enum")
1192-
),
1168+
ext_cx.expr_var(span, ~"__d"),
1169+
ext_cx.ident_of(~"read_enum"),
11931170
~[
11941171
ext_cx.lit_str(span, @ext_cx.str_of(name)),
11951172
expr_lambda

src/libsyntax/ext/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ pub fn mk_addr_of(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
111111
pub fn mk_mut_addr_of(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
112112
return mk_expr(cx, sp, ast::expr_addr_of(ast::m_mutbl, e));
113113
}
114+
pub fn mk_method_call(cx: @ext_ctxt,
115+
sp: span,
116+
rcvr_expr: @ast::expr,
117+
method_ident: ast::ident,
118+
+args: ~[@ast::expr]) -> @ast::expr {
119+
mk_expr(cx, sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar))
120+
}
114121
pub fn mk_call_(cx: @ext_ctxt, sp: span, fn_expr: @ast::expr,
115122
+args: ~[@ast::expr]) -> @ast::expr {
116123
mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar))

src/libsyntax/ext/deriving/clone.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ fn call_substructure_clone_method(cx: @ext_ctxt,
120120
-> @expr {
121121
// Call the substructure method.
122122
let clone_ident = cx.ident_of(~"clone");
123-
let self_method = build::mk_access_(cx, span, self_field, clone_ident);
124-
build::mk_call_(cx, span, self_method, ~[])
123+
build::mk_method_call(cx, span,
124+
self_field, clone_ident,
125+
~[])
125126
}
126127

127128
fn expand_deriving_clone_struct_def(cx: @ext_ctxt,

src/libsyntax/ext/deriving/eq.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,9 @@ fn call_substructure_eq_method(cx: @ext_ctxt,
147147
junction: Junction,
148148
chain_expr: &mut Option<@expr>) {
149149
// Call the substructure method.
150-
let self_method = build::mk_access_(cx, span, self_field, method_ident);
151-
let self_call = build::mk_call_(cx,
152-
span,
153-
self_method,
154-
~[ other_field_ref ]);
150+
let self_call = build::mk_method_call(cx, span,
151+
self_field, method_ident,
152+
~[ other_field_ref ]);
155153

156154
// Connect to the outer expression if necessary.
157155
*chain_expr = match *chain_expr {

src/libsyntax/ext/deriving/iter_bytes.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ fn call_substructure_iter_bytes_method(cx: @ext_ctxt,
125125

126126
// Call the substructure method.
127127
let iter_bytes_ident = cx.ident_of(~"iter_bytes");
128-
let self_method = build::mk_access_(cx,
129-
span,
130-
self_field,
131-
iter_bytes_ident);
132-
let self_call = build::mk_call_(cx,
133-
span,
134-
self_method,
135-
~[ lsb0_expr, f_expr ]);
128+
let self_call = build::mk_method_call(cx,
129+
span,
130+
self_field,
131+
iter_bytes_ident,
132+
~[ lsb0_expr, f_expr ]);
136133

137134
// Create a statement out of this expression.
138135
build::mk_stmt(cx, span, self_call)

0 commit comments

Comments
 (0)