Skip to content

Commit

Permalink
typeck/expr.rs: move check_method_call here.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jun 15, 2019
1 parent 819c4f2 commit 5ee36b7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 47 deletions.
51 changes: 50 additions & 1 deletion src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ use crate::check::Expectation::{self, NoExpectation, ExpectHasType, ExpectCastab
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};
Expand Down Expand Up @@ -772,6 +775,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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,
Expand Down
46 changes: 0 additions & 46 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3266,52 +3266,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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,
Expand Down

0 comments on commit 5ee36b7

Please sign in to comment.