1
Fork 0

Skip method calls with arity mismatch

This commit is contained in:
Martin Gammelsæter 2023-02-15 18:45:20 +01:00
parent 08cc628e73
commit e159c1e0ec
3 changed files with 8 additions and 11 deletions

View file

@ -298,6 +298,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// call's arguments and we can provide a more explicit span.
let sig = self.tcx.fn_sig(def_id).subst_identity();
let def_self_ty = sig.input(0).skip_binder();
let param_tys = sig.inputs().skip_binder().iter().skip(1);
// If there's an arity mismatch, pointing out the call as the source of an inference
// can be misleading, so we skip it.
if param_tys.len() != args.len() {
continue;
}
let rcvr_ty = self.node_ty(rcvr.hir_id);
// Get the evaluated type *after* calling the method call, so that the influence
// of the arguments can be reflected in the receiver type. The receiver
@ -323,7 +329,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut param_found = FxHashMap::default();
if self.can_eq(self.param_env, ty, found).is_ok() {
// We only point at the first place where the found type was inferred.
for (param_ty, arg) in sig.inputs().skip_binder().iter().skip(1).zip(args) {
for (param_ty, arg) in param_tys.zip(args) {
if def_self_ty.contains(*param_ty) && let ty::Param(_) = param_ty.kind() {
// We found an argument that references a type parameter in `Self`,
// so we assume that this is the argument that caused the found

View file

@ -13,8 +13,6 @@ fn main() {
//~^ ERROR this method takes 2 arguments but 1 argument was supplied
//~| NOTE an argument is missing
//~| HELP provide the argument
//~| NOTE this is of type `i32`, which causes `s` to be inferred as `S<i32, _>`
//~| HELP change the type of the numeric literal from `i32` to `u32`
let t: S<u32, _> = s;
//~^ ERROR mismatched types
//~| NOTE expected `S<u32, _>`, found `S<i32, _>`

View file

@ -15,11 +15,8 @@ LL | s.infer(0i32, /* b */);
| ~~~~~~~~~~~~~~~
error[E0308]: mismatched types
--> $DIR/point-at-inference-4.rs:18:24
--> $DIR/point-at-inference-4.rs:16:24
|
LL | s.infer(0i32);
| ---- this is of type `i32`, which causes `s` to be inferred as `S<i32, _>`
...
LL | let t: S<u32, _> = s;
| --------- ^ expected `S<u32, _>`, found `S<i32, _>`
| |
@ -27,10 +24,6 @@ LL | let t: S<u32, _> = s;
|
= note: expected struct `S<u32, _>`
found struct `S<i32, _>`
help: change the type of the numeric literal from `i32` to `u32`
|
LL | s.infer(0u32);
| ~~~
error: aborting due to 2 previous errors