Inline check_method_argument_types and remove error_reported special casing (unnecessary)

This commit is contained in:
Michael Goulet 2025-04-30 03:13:59 +00:00
parent 6aa3dd1943
commit f986d124f1
2 changed files with 36 additions and 62 deletions

View file

@ -50,8 +50,8 @@ use crate::errors::{
YieldExprOutsideOfCoroutine,
};
use crate::{
BreakableCtxt, CoroutineTypes, Diverges, FnCtxt, Needs, cast, fatally_break_rust,
report_unexpected_variant_res, type_error_struct,
BreakableCtxt, CoroutineTypes, Diverges, FnCtxt, Needs, TupleArgumentsFlag, cast,
fatally_break_rust, report_unexpected_variant_res, type_error_struct,
};
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@ -1590,21 +1590,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args)
{
match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args) {
Ok(method) => {
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
// trigger this codepath causing `structurally_resolve_type` to emit an error.
self.write_method_call_and_enforce_effects(expr.hir_id, expr.span, method);
Ok(method)
self.check_argument_types(
segment.ident.span,
expr,
&method.sig.inputs()[1..],
method.sig.output(),
expected,
args,
method.sig.c_variadic,
TupleArgumentsFlag::DontTupleArguments,
Some(method.def_id),
);
method.sig.output()
}
Err(error) => {
Err(self.report_method_error(expr.hir_id, rcvr_t, error, expected, false))
}
};
let guar = self.report_method_error(expr.hir_id, rcvr_t, error, expected, false);
// Call the generic checker.
self.check_method_argument_types(segment.ident.span, expr, method, args, expected)
let err_inputs = self.err_args(args.len(), guar);
let err_output = Ty::new_error(self.tcx, guar);
self.check_argument_types(
segment.ident.span,
expr,
&err_inputs,
err_output,
NoExpectation,
args,
false,
TupleArgumentsFlag::DontTupleArguments,
None,
);
err_output
}
}
}
/// Checks use `x.use`.

View file

@ -33,7 +33,6 @@ use crate::fn_ctxt::arg_matrix::{ArgMatrix, Compatibility, Error, ExpectedIdx, P
use crate::fn_ctxt::infer::FnCall;
use crate::gather_locals::Declaration;
use crate::inline_asm::InlineAsmCtxt;
use crate::method::MethodCallee;
use crate::method::probe::IsSuggestion;
use crate::method::probe::Mode::MethodCall;
use crate::method::probe::ProbeScope::TraitsInScope;
@ -127,55 +126,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
pub(in super::super) fn check_method_argument_types(
&self,
sp: Span,
expr: &'tcx hir::Expr<'tcx>,
method: Result<MethodCallee<'tcx>, ErrorGuaranteed>,
args_no_rcvr: &'tcx [hir::Expr<'tcx>],
expected: Expectation<'tcx>,
) -> Ty<'tcx> {
let has_error = match method {
Ok(method) => method.args.error_reported().and(method.sig.error_reported()),
Err(guar) => Err(guar),
};
if let Err(guar) = has_error {
let err_inputs = self.err_args(
method.map_or(args_no_rcvr.len(), |method| method.sig.inputs().len() - 1),
guar,
);
let err_output = Ty::new_error(self.tcx, guar);
self.check_argument_types(
sp,
expr,
&err_inputs,
err_output,
NoExpectation,
args_no_rcvr,
false,
TupleArgumentsFlag::DontTupleArguments,
method.ok().map(|method| method.def_id),
);
return err_output;
}
let method = method.unwrap();
self.check_argument_types(
sp,
expr,
&method.sig.inputs()[1..],
method.sig.output(),
expected,
args_no_rcvr,
method.sig.c_variadic,
TupleArgumentsFlag::DontTupleArguments,
Some(method.def_id),
);
method.sig.output()
}
/// Generic function that factors out common logic from function calls,
/// method calls and overloaded operators.
pub(in super::super) fn check_argument_types(