-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #41488 - estebank:closure-args, r=arielb1
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.
- Loading branch information
Showing
16 changed files
with
399 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2016 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 foo<F: Fn(usize)>(x: F) { } | ||
|
||
fn main() { | ||
foo(|y: String| { }); | ||
//~^ ERROR E0281 | ||
//~| ERROR E0281 | ||
//~| NOTE implements | ||
//~| NOTE implements | ||
//~| NOTE requires | ||
//~| NOTE requires | ||
//~| NOTE expected usize, found struct `std::string::String` | ||
//~| NOTE expected usize, found struct `std::string::String` | ||
//~| NOTE required by `foo` | ||
//~| NOTE required by `foo` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0281]: type mismatch: `[closure@$DIR/E0281.rs:14:9: 14:24]` implements the trait `std::ops::Fn<(std::string::String,)>`, but the trait `std::ops::Fn<(usize,)>` is required | ||
--> $DIR/E0281.rs:14:5 | ||
| | ||
14 | foo(|y: String| { }); | ||
| ^^^ --------------- implements `std::ops::Fn<(std::string::String,)>` | ||
| | | ||
| requires `std::ops::Fn<(usize,)>` | ||
| expected usize, found struct `std::string::String` | ||
| | ||
= note: required by `foo` | ||
|
||
error[E0281]: type mismatch: `[closure@$DIR/E0281.rs:14:9: 14:24]` implements the trait `std::ops::FnOnce<(std::string::String,)>`, but the trait `std::ops::FnOnce<(usize,)>` is required | ||
--> $DIR/E0281.rs:14:5 | ||
| | ||
14 | foo(|y: String| { }); | ||
| ^^^ --------------- implements `std::ops::FnOnce<(std::string::String,)>` | ||
| | | ||
| requires `std::ops::FnOnce<(usize,)>` | ||
| expected usize, found struct `std::string::String` | ||
| | ||
= note: required by `foo` | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.