-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Clean up callable type mismatch errors #41488
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
[1, 2, 3].sort_by(|tuple| panic!()); | ||
[1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
trait Foo {} | ||
|
||
impl<T: Fn(&())> Foo for T {} | ||
|
||
fn baz<T: Foo>(_: T) {} | ||
|
||
fn main() { | ||
baz(|_| ()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/closure-mismatch.rs:18:9: 18:15] as std::ops::FnOnce<(&'r (),)>>::Output == ()` | ||
--> $DIR/closure-mismatch.rs:18:5 | ||
| | ||
18 | baz(|_| ()); | ||
| ^^^ expected bound lifetime parameter, found concrete lifetime | ||
| | ||
= note: concrete lifetime that was found is lifetime '_#0r | ||
= note: required because of the requirements on the impl of `Foo` for `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two notes don't seem helplful. Are they what is there currently, rather than being added by this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's already part of the current output. I would prefer to remove them in a separate (smaller) PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that's fine |
||
= note: required by `baz` | ||
|
||
error[E0594]: closure mismatch: `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]` implements the trait `std::ops::Fn<(_,)>`, but the trait `for<'r> std::ops::Fn<(&'r (),)>` is required | ||
--> $DIR/closure-mismatch.rs:18:5 | ||
| | ||
18 | baz(|_| ()); | ||
| ^^^ ------ expected concrete lifetime, found bound lifetime parameter | ||
| | ||
= note: required because of the requirements on the impl of `Foo` for `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]` | ||
= note: required by `baz` | ||
|
||
error: aborting due to 2 previous errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you match on
expected_trait_ref
&actual_trait_ref
, to avoidFn(X<()>)
vs.Fn(X<(Foo, Bar)>)
etc.Also, this error message is probably good for all
Fn()
trait users, even if they are not closures.