Clean up closure type mismatch errors
This commit is contained in:
parent
2bd4b5c6db
commit
e8cf5f3662
7 changed files with 173 additions and 8 deletions
14
src/test/ui/mismatched_types/closure-arg-count.rs
Normal file
14
src/test/ui/mismatched_types/closure-arg-count.rs
Normal file
|
|
@ -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!());
|
||||
}
|
||||
43
src/test/ui/mismatched_types/closure-arg-count.stderr
Normal file
43
src/test/ui/mismatched_types/closure-arg-count.stderr
Normal file
|
|
@ -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
|
||||
|
||||
19
src/test/ui/mismatched_types/closure-mismatch.rs
Normal file
19
src/test/ui/mismatched_types/closure-mismatch.rs
Normal file
|
|
@ -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(|_| ());
|
||||
}
|
||||
21
src/test/ui/mismatched_types/closure-mismatch.stderr
Normal file
21
src/test/ui/mismatched_types/closure-mismatch.stderr
Normal file
|
|
@ -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]`
|
||||
= 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue