Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a numerical underflow in tuple wrap suggestion #99483

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If so, we might have just forgotten to wrap some args in a tuple.
if let Some(ty::Tuple(tys)) =
formal_and_expected_inputs.get(mismatch_idx.into()).map(|tys| tys.1.kind())
// If the tuple is unit, we're not actually wrapping any arguments.
&& !tys.is_empty()
&& provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len()
{
// Wrap up the N provided arguments starting at this position in a tuple.
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/argument-suggestions/issue-99482.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
let f = |_: (), f: fn()| f;
let _f = f(main);
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
}
19 changes: 19 additions & 0 deletions src/test/ui/argument-suggestions/issue-99482.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0057]: this function takes 2 arguments but 1 argument was supplied
--> $DIR/issue-99482.rs:3:14
|
LL | let _f = f(main);
| ^ ---- an argument of type `()` is missing
|
note: closure defined here
--> $DIR/issue-99482.rs:2:13
|
LL | let f = |_: (), f: fn()| f;
| ^^^^^^^^^^^^^^^^
help: provide the argument
|
LL | let _f = f((), main);
| ~~~~~~~~~~~

error: aborting due to previous error

For more information about this error, try `rustc --explain E0057`.