Skip to content

Commit 78bbc64

Browse files
Fix closure arg extraction in extract_callable_info
1 parent 7c7bb7d commit 78bbc64

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
10911091
Some((
10921092
DefIdOrName::DefId(def_id),
10931093
fn_sig.output(),
1094-
fn_sig.inputs().map_bound(|inputs| &inputs[1..]),
1094+
fn_sig.inputs().map_bound(|inputs| inputs[0].tuple_fields().as_slice()),
10951095
))
10961096
}
10971097
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
@@ -1101,7 +1101,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11011101
.iter()
11021102
.find_map(|pred| {
11031103
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
1104-
&& self.tcx.is_lang_item(proj.projection_term.def_id,LangItem::FnOnceOutput)
1104+
&& self.tcx.is_lang_item(proj.projection_term.def_id, LangItem::FnOnceOutput)
11051105
// args tuple will always be args[1]
11061106
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
11071107
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Ensure we give the right args when we suggest calling a closure.
2+
3+
fn main() {
4+
let x = |a: i32, b: i32| a + b;
5+
let y: i32 = x;
6+
//~^ ERROR mismatched types
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/correct-args-on-call-suggestion.rs:5:18
3+
|
4+
LL | let x = |a: i32, b: i32| a + b;
5+
| ---------------- the found closure
6+
LL | let y: i32 = x;
7+
| --- ^ expected `i32`, found closure
8+
| |
9+
| expected due to this
10+
|
11+
= note: expected type `i32`
12+
found closure `{closure@$DIR/correct-args-on-call-suggestion.rs:4:13: 4:29}`
13+
help: use parentheses to call this closure
14+
|
15+
LL | let y: i32 = x(/* i32 */, /* i32 */);
16+
| ++++++++++++++++++++++
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)