From 5ee36b7ecafc873ae15c4a4aa74f8293103b14c9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 15 Jun 2019 03:11:36 +0200 Subject: [PATCH] typeck/expr.rs: move check_method_call here. --- src/librustc_typeck/check/expr.rs | 51 ++++++++++++++++++++++++++++++- src/librustc_typeck/check/mod.rs | 46 ---------------------------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 7aa47a1a3a1..b133526054f 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -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, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0cc86744cc9..ae894a11452 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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, -- 2.44.0