-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,13 @@ fn apply<T, F>(t: T, f: F) where F: FnOnce(T) { | |
fn main() { | ||
apply(&3, takes_imm); | ||
apply(&3, takes_mut); | ||
//~^ ERROR (types differ in mutability) | ||
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. same |
||
//~^ ERROR type mismatch | ||
//~| NOTE types differ in mutability | ||
//~| NOTE required by `apply` | ||
|
||
apply(&mut 3, takes_mut); | ||
apply(&mut 3, takes_imm); | ||
//~^ ERROR (types differ in mutability) | ||
//~^ ERROR type mismatch | ||
//~| NOTE types differ in mutability | ||
//~| NOTE required by `apply` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,11 @@ fn main() { | |
//~^ ERROR no method named `count` | ||
//~| ERROR E0281 | ||
//~| ERROR E0281 | ||
//~| NOTE expected &str, found str | ||
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. same |
||
//~| NOTE expected &str, found str | ||
//~| NOTE implements | ||
//~| NOTE implements | ||
//~| NOTE requires | ||
//~| NOTE requires | ||
//~| NOTE the method `count` exists but the following trait bounds | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,16 @@ fn call_it<F:FnMut(isize,isize)->isize>(y: isize, mut f: F) -> isize { | |
|
||
pub fn main() { | ||
let f = to_fn_mut(|x: usize, y: isize| -> isize { (x as isize) + y }); | ||
//~^ NOTE implements | ||
//~| NOTE implements | ||
let z = call_it(3, f); | ||
//~^ ERROR type mismatch | ||
//~| ERROR type mismatch | ||
//~| NOTE expected isize, found usize | ||
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. same 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. Done for all. |
||
//~| NOTE expected isize, found usize | ||
//~| NOTE requires | ||
//~| NOTE requires | ||
//~| NOTE required by `call_it` | ||
//~| NOTE required by `call_it` | ||
println!("{}", z); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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(|| panic!()); | ||
[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,59 @@ | ||
error[E0593]: closure takes 0 arguments but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:12:15 | ||
| | ||
12 | [1, 2, 3].sort_by(|| panic!()); | ||
| ^^^^^^^ ----------- takes 0 arguments | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0593]: closure takes 0 arguments but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:12:15 | ||
| | ||
12 | [1, 2, 3].sort_by(|| panic!()); | ||
| ^^^^^^^ ----------- takes 0 arguments | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0593]: closure takes 1 argument but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:13:15 | ||
| | ||
13 | [1, 2, 3].sort_by(|tuple| panic!()); | ||
| ^^^^^^^ ---------------- takes 1 argument | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0593]: closure takes 1 argument but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:13:15 | ||
| | ||
13 | [1, 2, 3].sort_by(|tuple| panic!()); | ||
| ^^^^^^^ ---------------- takes 1 argument | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/closure-arg-count.rs:14:24 | ||
| | ||
14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
| ^^^^^^^^^^^^^^^ expected &{integer}, found tuple | ||
| | ||
= note: expected type `&{integer}` | ||
found type `(_, _)` | ||
|
||
error[E0593]: closure takes 1 argument but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:14:15 | ||
| | ||
14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
| ^^^^^^^ -------------------------- takes 1 argument | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0593]: closure takes 1 argument but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:14:15 | ||
| | ||
14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
| ^^^^^^^ -------------------------- takes 1 argument | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error: aborting due to 7 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(|_| ()); | ||
} |
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.
Can we move this to a
ui
test?