Skip to content

Commit 21ec0c8

Browse files
committed
rustc_typeck: don't use double indirection to Expr's in check_argument_types.
1 parent 2c76710 commit 21ec0c8

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/librustc_typeck/check/callee.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
192192
fcx.normalize_associated_types_in(call_expr.span, &fn_sig);
193193

194194
// Call the generic checker.
195-
let arg_exprs: Vec<_> = arg_exprs.iter().collect(); // for some weird reason we take &[&P<...>].
196195
check_argument_types(fcx,
197196
call_expr.span,
198197
fn_sig.inputs.as_slice(),
199-
arg_exprs.as_slice(),
198+
arg_exprs,
200199
AutorefArgs::No,
201200
fn_sig.variadic,
202201
TupleArgumentsFlag::DontTupleArguments);
@@ -209,12 +208,11 @@ fn confirm_overloaded_call<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
209208
arg_exprs: &[P<ast::Expr>],
210209
method_callee: ty::MethodCallee<'tcx>)
211210
{
212-
let arg_exprs: Vec<_> = arg_exprs.iter().collect(); // for some weird reason we take &[&P<...>].
213211
let output_type = check_method_argument_types(fcx,
214212
call_expr.span,
215213
method_callee.ty,
216214
call_expr,
217-
arg_exprs.as_slice(),
215+
arg_exprs,
218216
AutorefArgs::No,
219217
TupleArgumentsFlag::TupleArguments);
220218
let method_call = ty::MethodCall::expr(call_expr.id);

src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ use std::cell::{Cell, Ref, RefCell};
112112
use std::mem::replace;
113113
use std::rc::Rc;
114114
use std::iter::repeat;
115+
use std::slice;
115116
use syntax::{self, abi, attr};
116117
use syntax::ast::{self, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId};
117118
use syntax::ast_util::{self, local_def, PostExpansionMethod};
@@ -2598,7 +2599,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
25982599
sp: Span,
25992600
method_fn_ty: Ty<'tcx>,
26002601
callee_expr: &ast::Expr,
2601-
args_no_rcvr: &[&P<ast::Expr>],
2602+
args_no_rcvr: &[P<ast::Expr>],
26022603
autoref_args: AutorefArgs,
26032604
tuple_arguments: TupleArgumentsFlag)
26042605
-> ty::FnOutput<'tcx> {
@@ -2624,7 +2625,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26242625
// HACK(eddyb) ignore self in the definition (see above).
26252626
check_argument_types(fcx,
26262627
sp,
2627-
fty.sig.0.inputs.slice_from(1),
2628+
&fty.sig.0.inputs[1..],
26282629
args_no_rcvr,
26292630
autoref_args,
26302631
fty.sig.0.variadic,
@@ -2644,7 +2645,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26442645
fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26452646
sp: Span,
26462647
fn_inputs: &[Ty<'tcx>],
2647-
args: &[&P<ast::Expr>],
2648+
args: &[P<ast::Expr>],
26482649
autoref_args: AutorefArgs,
26492650
variadic: bool,
26502651
tuple_arguments: TupleArgumentsFlag) {
@@ -2767,7 +2768,7 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
27672768
AutorefArgs::No => {}
27682769
}
27692770

2770-
check_expr_coercable_to_type(fcx, &***arg, formal_ty);
2771+
check_expr_coercable_to_type(fcx, &**arg, formal_ty);
27712772
}
27722773
}
27732774
}
@@ -2776,12 +2777,12 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
27762777
// arguments which we skipped above.
27772778
if variadic {
27782779
for arg in args.iter().skip(expected_arg_count) {
2779-
check_expr(fcx, &***arg);
2780+
check_expr(fcx, &**arg);
27802781

27812782
// There are a few types which get autopromoted when passed via varargs
27822783
// in C but we just error out instead and require explicit casts.
27832784
let arg_ty = structurally_resolved_type(fcx, arg.span,
2784-
fcx.expr_ty(&***arg));
2785+
fcx.expr_ty(&**arg));
27852786
match arg_ty.sty {
27862787
ty::ty_float(ast::TyF32) => {
27872788
fcx.type_error_message(arg.span,
@@ -3064,12 +3065,11 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
30643065
};
30653066

30663067
// Call the generic checker.
3067-
let args: Vec<_> = args[1..].iter().map(|x| x).collect();
30683068
let ret_ty = check_method_argument_types(fcx,
30693069
method_name.span,
30703070
fn_ty,
30713071
expr,
3072-
args.as_slice(),
3072+
&args[1..],
30733073
AutorefArgs::No,
30743074
DontTupleArguments);
30753075

@@ -3167,8 +3167,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
31673167
None => None
31683168
};
31693169
let args = match rhs {
3170-
Some(rhs) => vec![rhs],
3171-
None => vec![]
3170+
Some(rhs) => slice::ref_slice(rhs),
3171+
None => &[][]
31723172
};
31733173
match method {
31743174
Some(method) => {
@@ -3177,12 +3177,12 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
31773177
let method_call = ::middle::ty::MethodCall::expr(op_ex.id);
31783178
fcx.inh.method_map.borrow_mut().insert(method_call, method);
31793179
match check_method_argument_types(fcx,
3180-
op_ex.span,
3181-
method_ty,
3182-
op_ex,
3183-
args.as_slice(),
3184-
autoref_args,
3185-
DontTupleArguments) {
3180+
op_ex.span,
3181+
method_ty,
3182+
op_ex,
3183+
args,
3184+
autoref_args,
3185+
DontTupleArguments) {
31863186
ty::FnConverging(result_type) => result_type,
31873187
ty::FnDiverging => fcx.tcx().types.err
31883188
}
@@ -3196,7 +3196,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
31963196
op_ex.span,
31973197
expected_ty,
31983198
op_ex,
3199-
args.as_slice(),
3199+
args,
32003200
autoref_args,
32013201
DontTupleArguments);
32023202
fcx.tcx().types.err
@@ -4045,10 +4045,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
40454045
fcx.write_ty(id, fcx.node_ty(b.id));
40464046
}
40474047
ast::ExprCall(ref callee, ref args) => {
4048-
callee::check_call(fcx, expr, &**callee, args.as_slice());
4048+
callee::check_call(fcx, expr, &**callee, &args[]);
40494049
}
40504050
ast::ExprMethodCall(ident, ref tps, ref args) => {
4051-
check_method_call(fcx, expr, ident, args.as_slice(), tps.as_slice(), lvalue_pref);
4051+
check_method_call(fcx, expr, ident, &args[], &tps[], lvalue_pref);
40524052
let arg_tys = args.iter().map(|a| fcx.expr_ty(&**a));
40534053
let args_err = arg_tys.fold(false,
40544054
|rest_err, a| {

0 commit comments

Comments
 (0)