1
Fork 0

Fix closure arg extraction in extract_callable_info

This commit is contained in:
Michael Goulet 2024-11-02 03:42:10 +00:00
parent 7c7bb7dc01
commit 78bbc648c5
3 changed files with 29 additions and 2 deletions

View file

@ -1091,7 +1091,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
Some(( Some((
DefIdOrName::DefId(def_id), DefIdOrName::DefId(def_id),
fn_sig.output(), fn_sig.output(),
fn_sig.inputs().map_bound(|inputs| &inputs[1..]), fn_sig.inputs().map_bound(|inputs| inputs[0].tuple_fields().as_slice()),
)) ))
} }
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {

View file

@ -0,0 +1,7 @@
// Ensure we give the right args when we suggest calling a closure.
fn main() {
let x = |a: i32, b: i32| a + b;
let y: i32 = x;
//~^ ERROR mismatched types
}

View file

@ -0,0 +1,20 @@
error[E0308]: mismatched types
--> $DIR/correct-args-on-call-suggestion.rs:5:18
|
LL | let x = |a: i32, b: i32| a + b;
| ---------------- the found closure
LL | let y: i32 = x;
| --- ^ expected `i32`, found closure
| |
| expected due to this
|
= note: expected type `i32`
found closure `{closure@$DIR/correct-args-on-call-suggestion.rs:4:13: 4:29}`
help: use parentheses to call this closure
|
LL | let y: i32 = x(/* i32 */, /* i32 */);
| ++++++++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.