-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Error message for wrong number of arguments to a closure is bad #21857
Comments
This is a very bad issue and there’s only a single report on it?! Need more ccs. Any thoughts on who would be good people to cc here, @nrc? |
This feels like a good candidate to batch with #33240 |
Dup of #24680 |
I am not so sure. That issue is about the HR |
@arielb1 I suppose the original issue was highlighting a smattering of things; seems ok to separate out tuples in particular, sure. |
Below are more examples of code and their bad error messages. Expected behaviour:
error[E0281]: type mismatch: the type `[closure@<anon>:3:23: 3:39]` implements the trait `for<'r> std::ops::FnMut<(&'r {integer},)>`, but the trait `for<'r, 'r> std::ops::FnMut<(&'r {integer}, &'r {integer})>` is required (expected a tuple with 2 elements, found one with 1 elements)
--> <anon>:3:15
|
3 | [1, 2, 3].sort_by(|tuple| panic!());
| ^^^^^^^
error[E0281]: type mismatch: the type `[closure@<anon>:3:23: 3:39]` implements the trait `for<'r> std::ops::FnOnce<(&'r {integer},)>`, but the trait `for<'r, 'r> std::ops::FnOnce<(&'r {integer}, &'r {integer})>` is required (expected a tuple with 2 elements, found one with 1 elements)
--> <anon>:3:15
|
3 | [1, 2, 3].sort_by(|tuple| panic!());
| ^^^^^^^
error[E0277]: the trait bound `for<'r, 'r> {integer}: std::ops::FnMut<(&'r {integer}, &'r {integer})>` is not satisfied
--> <anon>:4:15
|
4 | [1, 2, 3].sort_by(1);
| ^^^^^^^ the trait `for<'r, 'r> std::ops::FnMut<(&'r {integer}, &'r {integer})>` is not implemented for `{integer}`
|
= help: the following implementations were found:
= help: <&'a F as std::ops::FnMut<A>>
= help: <&'a mut F as std::ops::FnMut<A>>
= help: <core::str::LinesAnyMap as std::ops::FnMut<(&'a str,)>>
error[E0277]: the trait bound `for<'r, 'r> {integer}: std::ops::FnOnce<(&'r {integer}, &'r {integer})>` is not satisfied
--> <anon>:4:15
|
4 | [1, 2, 3].sort_by(1);
| ^^^^^^^ the trait `for<'r, 'r> std::ops::FnOnce<(&'r {integer}, &'r {integer})>` is not implemented for `{integer}`
|
= help: the following implementations were found:
= help: <&'a F as std::ops::FnOnce<A>>
= help: <&'a mut F as std::ops::FnOnce<A>>
= help: <core::str::LinesAnyMap as std::ops::FnOnce<(&'a str,)>>
= help: <Box<std::boxed::FnBox<A, Output=R> + 'a> as std::ops::FnOnce<A>>
= help: and 2 others error[E0308]: mismatched types
--> <anon>:3:24
|
3 | [1, 2, 3].sort_by(|(a, b)| panic!());
| ^^^^^^ expected &{integer}, found tuple
|
= note: expected type `&{integer}`
= note: found type `(_, _)`
error[E0281]: type mismatch: the type `[closure@<anon>:3:23: 3:40]` implements the trait `for<'r> std::ops::FnMut<(&'r {integer},)>`, but the trait `for<'r, 'r> std::ops::FnMut<(&'r {integer}, &'r {integer})>` is required (expected a tuple with 2 elements, found one with 1 elements)
--> <anon>:3:15
|
3 | [1, 2, 3].sort_by(|(a, b)| panic!());
| ^^^^^^^
error[E0281]: type mismatch: the type `[closure@<anon>:3:23: 3:40]` implements the trait `for<'r> std::ops::FnOnce<(&'r {integer},)>`, but the trait `for<'r, 'r> std::ops::FnOnce<(&'r {integer}, &'r {integer})>` is required (expected a tuple with 2 elements, found one with 1 elements)
--> <anon>:3:15
|
3 | [1, 2, 3].sort_by(|(a, b)| panic!());
| ^^^^^^^ |
I have a PR with this proposed output for the following file: fn main() {
[1, 2, 3].sort_by(|tuple| panic!());
[1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
} error[E0593]: closure takes 1 parameter but 2 parameters are required here
--> $DIR/closure-arg-count.rs:12:15
|
12 | [1, 2, 3].sort_by(|tuple| panic!());
| ^^^^^^^ ---------------- takes 1 parameter
| |
| expected closure that takes 2 parameters
error[E0593]: closure takes 1 parameter but 2 parameters are required here
--> $DIR/closure-arg-count.rs:12:15
|
12 | [1, 2, 3].sort_by(|tuple| panic!());
| ^^^^^^^ ---------------- takes 1 parameter
| |
| expected closure that takes 2 parameters
error[E0308]: mismatched types
--> $DIR/closure-arg-count.rs:13:24
|
13 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
| ^^^^^^^^^^^^^^^ expected &{integer}, found tuple
|
= note: expected type `&{integer}`
found type `(_, _)`
error[E0593]: closure takes 1 parameter but 2 parameters are required here
--> $DIR/closure-arg-count.rs:13:15
|
13 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
| ^^^^^^^ -------------------------- takes 1 parameter
| |
| expected closure that takes 2 parameters
error[E0593]: closure takes 1 parameter but 2 parameters are required here
--> $DIR/closure-arg-count.rs:13:15
|
13 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
| ^^^^^^^ -------------------------- takes 1 parameter
| |
| expected closure that takes 2 parameters
error: aborting due to 5 previous errors Any suggestions welcome. I'm looking at removing the duplicate messages, but that might have to be a separate PR. |
Clean up callable type mismatch errors ```rust error[E0593]: closure takes 1 argument but 2 arguments are required here --> ../../src/test/ui/mismatched_types/closure-arg-count.rs:13:15 | 13 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ^^^^^^^ -------------------------- takes 1 argument | | | expected closure that takes 2 arguments ``` instead of ```rust error[E0281]: type mismatch: the type `[closure@../../src/test/ui/mismatched_types/closure-arg-count.rs:13:23: 13:49]` implements the trait `for<'r> std::ops::FnMut<(&'r {integer},)>`, but the trait `for<'r, 'r> std::ops::FnMut<(&'r {integer}, &'r {integer})>` is required (expected a tuple with 2 elements, found one with 1 elements) --> ../../src/test/ui/mismatched_types/closure-arg-count.rs:13:15 | 13 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ^^^^^^^ ``` Fix #21857, re #24680.
For example:
error: type mismatch: the type `[closure /home/ncameron/rust3/src/librustc_driver/lib.rs:107:36: 107:44]` implements the trait `for<'r> core::ops::Fn<(&'r rustc::session::Session,)>`, but the trait `for<'r,'r> core::ops::Fn<(&'r rustc::session::Session, &'r getopts::Matches)>` is required (expected a tuple with 2 elements, found one with 1 elements)
It should talk about arguments rather than tuples, it should also be multi-line. It probably doesn't need to talk about the
Fn
trait at all.The text was updated successfully, but these errors were encountered: