Skip to content

Commit d9a71c1

Browse files
authored
Rollup merge of rust-lang#99483 - compiler-errors:issue-99482, r=jyn514
Fix a numerical underflow in tuple wrap suggestion Fixes rust-lang#99482 I'm a clown, I rewrote the arg mismatch algo to use well-typed indices to avoid things like this, but then I added my own indexing bug, lol.
2 parents fffc650 + 43c0c63 commit d9a71c1

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
@@ -573,6 +573,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
573573
// If so, we might have just forgotten to wrap some args in a tuple.
574574
if let Some(ty::Tuple(tys)) =
575575
formal_and_expected_inputs.get(mismatch_idx.into()).map(|tys| tys.1.kind())
576+
// If the tuple is unit, we're not actually wrapping any arguments.
577+
&& !tys.is_empty()
576578
&& provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len()
577579
{
578580
// 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)