typeck/expr.rs: move check_method_call here.

This commit is contained in:
Mazdak Farrokhzad 2019-06-15 03:11:36 +02:00
parent 819c4f2f08
commit 5ee36b7eca
2 changed files with 50 additions and 47 deletions

View File

@ -11,13 +11,16 @@
use crate::check::fatally_break_rust;
use crate::check::report_unexpected_variant_res;
use crate::check::Needs;
use crate::check::TupleArgumentsFlag::DontTupleArguments;
use crate::check::method::SelfSource;
use crate::middle::lang_items;
use crate::util::common::ErrorReported;
use errors::Applicability;
use syntax::ast;
use syntax::ptr::P;
use syntax::symbol::sym;
use syntax::symbol::{kw, sym};
use syntax::source_map::Span;
use rustc::hir;
use rustc::hir::{ExprKind, QPath};
use rustc::hir::def::{CtorKind, Res, DefKind};
@ -772,6 +775,52 @@ fn check_expr_loop(
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit())
}
/// Checks a method call.
fn check_method_call(
&self,
expr: &'tcx hir::Expr,
segment: &hir::PathSegment,
span: Span,
args: &'tcx [hir::Expr],
expected: Expectation<'tcx>,
needs: Needs,
) -> Ty<'tcx> {
let rcvr = &args[0];
let rcvr_t = self.check_expr_with_needs(&rcvr, needs);
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
let method = match self.lookup_method(rcvr_t,
segment,
span,
expr,
rcvr) {
Ok(method) => {
self.write_method_call(expr.hir_id, method);
Ok(method)
}
Err(error) => {
if segment.ident.name != kw::Invalid {
self.report_method_error(span,
rcvr_t,
segment.ident,
SelfSource::MethodCall(rcvr),
error,
Some(args));
}
Err(())
}
};
// Call the generic checker.
self.check_method_argument_types(span,
expr.span,
method,
&args[1..],
DontTupleArguments,
expected)
}
fn check_expr_cast(
&self,
e: &'tcx hir::Expr,

View File

@ -3266,52 +3266,6 @@ fn expected_inputs_for_expected_output(&self,
expect_args
}
// Checks a method call.
fn check_method_call(
&self,
expr: &'tcx hir::Expr,
segment: &hir::PathSegment,
span: Span,
args: &'tcx [hir::Expr],
expected: Expectation<'tcx>,
needs: Needs,
) -> Ty<'tcx> {
let rcvr = &args[0];
let rcvr_t = self.check_expr_with_needs(&rcvr, needs);
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
let method = match self.lookup_method(rcvr_t,
segment,
span,
expr,
rcvr) {
Ok(method) => {
self.write_method_call(expr.hir_id, method);
Ok(method)
}
Err(error) => {
if segment.ident.name != kw::Invalid {
self.report_method_error(span,
rcvr_t,
segment.ident,
SelfSource::MethodCall(rcvr),
error,
Some(args));
}
Err(())
}
};
// Call the generic checker.
self.check_method_argument_types(span,
expr.span,
method,
&args[1..],
DontTupleArguments,
expected)
}
// Check field access expressions
fn check_field(
&self,