Skip to content

Commit 3c1ef01

Browse files
compiler-errorsehuss
authored andcommitted
beta backport of arg mismatch bugfix
1 parent 4766af1 commit 3c1ef01

File tree

7 files changed

+51
-22
lines changed

7 files changed

+51
-22
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303303

304304
let provided_arg: &hir::Expr<'tcx> = &provided_args[input_idx];
305305
let expectation = Expectation::rvalue_hint(self, expected_input_ty);
306-
// FIXME: check that this is safe; I don't believe this commits any of the obligations, but I can't be sure.
307-
//
308-
// I had another method of "soft" type checking before,
309-
// but it was failing to find the type of some expressions (like "")
310-
// so I prodded this method and made it pub(super) so I could call it, and it seems to work well.
311-
let checked_ty = self.check_expr_kind(provided_arg, expectation);
306+
let already_checked_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(provided_arg);
307+
let checked_ty = already_checked_ty.unwrap_or_else(|| self.check_expr(provided_arg));
312308

313309
let coerced_ty = expectation.only_has_type(self).unwrap_or(formal_input_ty);
314310
let can_coerce = self.can_coerce(checked_ty, coerced_ty);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
(|_, ()| ())(if true {} else {return;});
3+
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
4+
}
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-98894.rs:2:5
3+
|
4+
LL | (|_, ()| ())(if true {} else {return;});
5+
| ^^^^^^^^^^^^--------------------------- an argument of type `()` is missing
6+
|
7+
note: closure defined here
8+
--> $DIR/issue-98894.rs:2:6
9+
|
10+
LL | (|_, ()| ())(if true {} else {return;});
11+
| ^^^^^^^
12+
help: provide the argument
13+
|
14+
LL | (|_, ()| ())(if true {} else {return;}, ());
15+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0057`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
(|_, ()| ())([return, ()]);
3+
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
4+
}
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-98897.rs:2:5
3+
|
4+
LL | (|_, ()| ())([return, ()]);
5+
| ^^^^^^^^^^^^-------------- an argument of type `()` is missing
6+
|
7+
note: closure defined here
8+
--> $DIR/issue-98897.rs:2:6
9+
|
10+
LL | (|_, ()| ())([return, ()]);
11+
| ^^^^^^^
12+
help: provide the argument
13+
|
14+
LL | (|_, ()| ())([return, ()], ());
15+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0057`.

src/test/ui/issues/issue-3044.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ fn main() {
22
let needlesArr: Vec<char> = vec!['a', 'f'];
33
needlesArr.iter().fold(|x, y| {
44
});
5-
//~^^ ERROR mismatched types
6-
//~| ERROR this function takes 2 arguments but 1 argument was supplied
5+
//~^^ ERROR this function takes 2 arguments but 1 argument was supplied
76
}

src/test/ui/issues/issue-3044.stderr

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/issue-3044.rs:3:35
3-
|
4-
LL | needlesArr.iter().fold(|x, y| {
5-
| ___________________________________^
6-
LL | | });
7-
| |_____^ expected closure, found `()`
8-
|
9-
= note: expected closure `[closure@$DIR/issue-3044.rs:3:28: 4:6]`
10-
found unit type `()`
11-
121
error[E0061]: this function takes 2 arguments but 1 argument was supplied
132
--> $DIR/issue-3044.rs:3:23
143
|
@@ -28,7 +17,6 @@ LL ~ needlesArr.iter().fold(|x, y| {
2817
LL ~ }, /* value */);
2918
|
3019

31-
error: aborting due to 2 previous errors
20+
error: aborting due to previous error
3221

33-
Some errors have detailed explanations: E0061, E0308.
34-
For more information about an error, try `rustc --explain E0061`.
22+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)