Skip to content

Commit 5ee36b7

Browse files
committed
typeck/expr.rs: move check_method_call here.
1 parent 819c4f2 commit 5ee36b7

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

src/librustc_typeck/check/expr.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ use crate::check::Expectation::{self, NoExpectation, ExpectHasType, ExpectCastab
1111
use crate::check::fatally_break_rust;
1212
use crate::check::report_unexpected_variant_res;
1313
use crate::check::Needs;
14+
use crate::check::TupleArgumentsFlag::DontTupleArguments;
15+
use crate::check::method::SelfSource;
1416
use crate::middle::lang_items;
1517
use crate::util::common::ErrorReported;
1618

1719
use errors::Applicability;
1820
use syntax::ast;
1921
use syntax::ptr::P;
20-
use syntax::symbol::sym;
22+
use syntax::symbol::{kw, sym};
23+
use syntax::source_map::Span;
2124
use rustc::hir;
2225
use rustc::hir::{ExprKind, QPath};
2326
use rustc::hir::def::{CtorKind, Res, DefKind};
@@ -772,6 +775,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
772775
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit())
773776
}
774777

778+
/// Checks a method call.
779+
fn check_method_call(
780+
&self,
781+
expr: &'tcx hir::Expr,
782+
segment: &hir::PathSegment,
783+
span: Span,
784+
args: &'tcx [hir::Expr],
785+
expected: Expectation<'tcx>,
786+
needs: Needs,
787+
) -> Ty<'tcx> {
788+
let rcvr = &args[0];
789+
let rcvr_t = self.check_expr_with_needs(&rcvr, needs);
790+
// no need to check for bot/err -- callee does that
791+
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
792+
793+
let method = match self.lookup_method(rcvr_t,
794+
segment,
795+
span,
796+
expr,
797+
rcvr) {
798+
Ok(method) => {
799+
self.write_method_call(expr.hir_id, method);
800+
Ok(method)
801+
}
802+
Err(error) => {
803+
if segment.ident.name != kw::Invalid {
804+
self.report_method_error(span,
805+
rcvr_t,
806+
segment.ident,
807+
SelfSource::MethodCall(rcvr),
808+
error,
809+
Some(args));
810+
}
811+
Err(())
812+
}
813+
};
814+
815+
// Call the generic checker.
816+
self.check_method_argument_types(span,
817+
expr.span,
818+
method,
819+
&args[1..],
820+
DontTupleArguments,
821+
expected)
822+
}
823+
775824
fn check_expr_cast(
776825
&self,
777826
e: &'tcx hir::Expr,

src/librustc_typeck/check/mod.rs

-46
Original file line numberDiff line numberDiff line change
@@ -3266,52 +3266,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32663266
expect_args
32673267
}
32683268

3269-
// Checks a method call.
3270-
fn check_method_call(
3271-
&self,
3272-
expr: &'tcx hir::Expr,
3273-
segment: &hir::PathSegment,
3274-
span: Span,
3275-
args: &'tcx [hir::Expr],
3276-
expected: Expectation<'tcx>,
3277-
needs: Needs,
3278-
) -> Ty<'tcx> {
3279-
let rcvr = &args[0];
3280-
let rcvr_t = self.check_expr_with_needs(&rcvr, needs);
3281-
// no need to check for bot/err -- callee does that
3282-
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
3283-
3284-
let method = match self.lookup_method(rcvr_t,
3285-
segment,
3286-
span,
3287-
expr,
3288-
rcvr) {
3289-
Ok(method) => {
3290-
self.write_method_call(expr.hir_id, method);
3291-
Ok(method)
3292-
}
3293-
Err(error) => {
3294-
if segment.ident.name != kw::Invalid {
3295-
self.report_method_error(span,
3296-
rcvr_t,
3297-
segment.ident,
3298-
SelfSource::MethodCall(rcvr),
3299-
error,
3300-
Some(args));
3301-
}
3302-
Err(())
3303-
}
3304-
};
3305-
3306-
// Call the generic checker.
3307-
self.check_method_argument_types(span,
3308-
expr.span,
3309-
method,
3310-
&args[1..],
3311-
DontTupleArguments,
3312-
expected)
3313-
}
3314-
33153269
// Check field access expressions
33163270
fn check_field(
33173271
&self,

0 commit comments

Comments
 (0)