Skip to content

Commit f986d12

Browse files
Inline check_method_argument_types and remove error_reported special casing (unnecessary)
1 parent 6aa3dd1 commit f986d12

File tree

2 files changed

+36
-62
lines changed

2 files changed

+36
-62
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+36-12
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ use crate::errors::{
5050
YieldExprOutsideOfCoroutine,
5151
};
5252
use crate::{
53-
BreakableCtxt, CoroutineTypes, Diverges, FnCtxt, Needs, cast, fatally_break_rust,
54-
report_unexpected_variant_res, type_error_struct,
53+
BreakableCtxt, CoroutineTypes, Diverges, FnCtxt, Needs, TupleArgumentsFlag, cast,
54+
fatally_break_rust, report_unexpected_variant_res, type_error_struct,
5555
};
5656

5757
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -1590,21 +1590,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15901590
// no need to check for bot/err -- callee does that
15911591
let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
15921592

1593-
let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args)
1594-
{
1593+
match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args) {
15951594
Ok(method) => {
1596-
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
1597-
// trigger this codepath causing `structurally_resolve_type` to emit an error.
15981595
self.write_method_call_and_enforce_effects(expr.hir_id, expr.span, method);
1599-
Ok(method)
1596+
1597+
self.check_argument_types(
1598+
segment.ident.span,
1599+
expr,
1600+
&method.sig.inputs()[1..],
1601+
method.sig.output(),
1602+
expected,
1603+
args,
1604+
method.sig.c_variadic,
1605+
TupleArgumentsFlag::DontTupleArguments,
1606+
Some(method.def_id),
1607+
);
1608+
1609+
method.sig.output()
16001610
}
16011611
Err(error) => {
1602-
Err(self.report_method_error(expr.hir_id, rcvr_t, error, expected, false))
1603-
}
1604-
};
1612+
let guar = self.report_method_error(expr.hir_id, rcvr_t, error, expected, false);
16051613

1606-
// Call the generic checker.
1607-
self.check_method_argument_types(segment.ident.span, expr, method, args, expected)
1614+
let err_inputs = self.err_args(args.len(), guar);
1615+
let err_output = Ty::new_error(self.tcx, guar);
1616+
1617+
self.check_argument_types(
1618+
segment.ident.span,
1619+
expr,
1620+
&err_inputs,
1621+
err_output,
1622+
NoExpectation,
1623+
args,
1624+
false,
1625+
TupleArgumentsFlag::DontTupleArguments,
1626+
None,
1627+
);
1628+
1629+
err_output
1630+
}
1631+
}
16081632
}
16091633

16101634
/// Checks use `x.use`.

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

-50
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::fn_ctxt::arg_matrix::{ArgMatrix, Compatibility, Error, ExpectedIdx, P
3333
use crate::fn_ctxt::infer::FnCall;
3434
use crate::gather_locals::Declaration;
3535
use crate::inline_asm::InlineAsmCtxt;
36-
use crate::method::MethodCallee;
3736
use crate::method::probe::IsSuggestion;
3837
use crate::method::probe::Mode::MethodCall;
3938
use crate::method::probe::ProbeScope::TraitsInScope;
@@ -127,55 +126,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
127126
}
128127
}
129128

130-
pub(in super::super) fn check_method_argument_types(
131-
&self,
132-
sp: Span,
133-
expr: &'tcx hir::Expr<'tcx>,
134-
method: Result<MethodCallee<'tcx>, ErrorGuaranteed>,
135-
args_no_rcvr: &'tcx [hir::Expr<'tcx>],
136-
expected: Expectation<'tcx>,
137-
) -> Ty<'tcx> {
138-
let has_error = match method {
139-
Ok(method) => method.args.error_reported().and(method.sig.error_reported()),
140-
Err(guar) => Err(guar),
141-
};
142-
if let Err(guar) = has_error {
143-
let err_inputs = self.err_args(
144-
method.map_or(args_no_rcvr.len(), |method| method.sig.inputs().len() - 1),
145-
guar,
146-
);
147-
let err_output = Ty::new_error(self.tcx, guar);
148-
149-
self.check_argument_types(
150-
sp,
151-
expr,
152-
&err_inputs,
153-
err_output,
154-
NoExpectation,
155-
args_no_rcvr,
156-
false,
157-
TupleArgumentsFlag::DontTupleArguments,
158-
method.ok().map(|method| method.def_id),
159-
);
160-
return err_output;
161-
}
162-
163-
let method = method.unwrap();
164-
self.check_argument_types(
165-
sp,
166-
expr,
167-
&method.sig.inputs()[1..],
168-
method.sig.output(),
169-
expected,
170-
args_no_rcvr,
171-
method.sig.c_variadic,
172-
TupleArgumentsFlag::DontTupleArguments,
173-
Some(method.def_id),
174-
);
175-
176-
method.sig.output()
177-
}
178-
179129
/// Generic function that factors out common logic from function calls,
180130
/// method calls and overloaded operators.
181131
pub(in super::super) fn check_argument_types(

0 commit comments

Comments
 (0)