Skip to content

Commit 43c0c63

Browse files
Fix a numerical underflow in tuple wrap suggestion
1 parent 29c5a02 commit 43c0c63

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+2
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
575575
// If so, we might have just forgotten to wrap some args in a tuple.
576576
if let Some(ty::Tuple(tys)) =
577577
formal_and_expected_inputs.get(mismatch_idx.into()).map(|tys| tys.1.kind())
578+
// If the tuple is unit, we're not actually wrapping any arguments.
579+
&& !tys.is_empty()
578580
&& provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len()
579581
{
580582
// Wrap up the N provided arguments starting at this position in a tuple.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let f = |_: (), f: fn()| f;
3+
let _f = f(main);
4+
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0057]: this function takes 2 arguments but 1 argument was supplied
2+
--> $DIR/issue-99482.rs:3:14
3+
|
4+
LL | let _f = f(main);
5+
| ^ ---- an argument of type `()` is missing
6+
|
7+
note: closure defined here
8+
--> $DIR/issue-99482.rs:2:13
9+
|
10+
LL | let f = |_: (), f: fn()| f;
11+
| ^^^^^^^^^^^^^^^^
12+
help: provide the argument
13+
|
14+
LL | let _f = f((), main);
15+
| ~~~~~~~~~~~
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0057`.

0 commit comments

Comments
 (0)