Correct meaning of two UI tests

This commit is contained in:
Michael Goulet 2022-07-30 09:44:22 +00:00
parent 8b64988575
commit 1c084f15f3
4 changed files with 45 additions and 34 deletions

View File

@ -1,11 +1,11 @@
#![feature(unboxed_closures)]
fn foo<F: Fn(usize)>(_: F) {}
fn bar<F: Fn<usize>>(_: F) {}
fn bar<F: Fn<(usize,)>>(_: F) {}
fn main() {
fn f(_: u64) {}
foo(|_: isize| {}); //~ ERROR type mismatch
bar(|_: isize| {}); //~ ERROR mismatched types
bar(|_: isize| {}); //~ ERROR type mismatch
foo(f); //~ ERROR type mismatch
bar(f); //~ ERROR mismatched types
bar(f); //~ ERROR type mismatch
}

View File

@ -14,19 +14,21 @@ note: required by a bound in `foo`
LL | fn foo<F: Fn(usize)>(_: F) {}
| ^^^^^^^^^ required by this bound in `foo`
error[E0308]: mismatched types
error[E0631]: type mismatch in closure arguments
--> $DIR/E0631.rs:8:5
|
LL | bar(|_: isize| {});
| ^^^ types differ
| ^^^ ---------- found signature defined here
| |
| expected due to this
|
= note: expected trait `Fn<usize>`
found trait `Fn<(isize,)>`
= note: expected closure signature `fn(usize) -> _`
found closure signature `fn(isize) -> _`
note: required by a bound in `bar`
--> $DIR/E0631.rs:4:11
|
LL | fn bar<F: Fn<usize>>(_: F) {}
| ^^^^^^^^^ required by this bound in `bar`
LL | fn bar<F: Fn<(usize,)>>(_: F) {}
| ^^^^^^^^^^^^ required by this bound in `bar`
error[E0631]: type mismatch in function arguments
--> $DIR/E0631.rs:9:9
@ -47,23 +49,25 @@ note: required by a bound in `foo`
LL | fn foo<F: Fn(usize)>(_: F) {}
| ^^^^^^^^^ required by this bound in `foo`
error[E0308]: mismatched types
error[E0631]: type mismatch in function arguments
--> $DIR/E0631.rs:10:9
|
LL | fn f(_: u64) {}
| ------------ found signature defined here
...
LL | bar(f);
| --- ^ types differ
| --- ^ expected due to this
| |
| required by a bound introduced by this call
|
= note: expected trait `Fn<usize>`
found trait `Fn<(u64,)>`
= note: expected function signature `fn(usize) -> _`
found function signature `fn(u64) -> _`
note: required by a bound in `bar`
--> $DIR/E0631.rs:4:11
|
LL | fn bar<F: Fn<usize>>(_: F) {}
| ^^^^^^^^^ required by this bound in `bar`
LL | fn bar<F: Fn<(usize,)>>(_: F) {}
| ^^^^^^^^^^^^ required by this bound in `bar`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0308, E0631.
For more information about an error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0631`.

View File

@ -1,6 +1,6 @@
#![feature(unboxed_closures)]
fn f<F: Fn<usize>>(_: F) {}
fn f<F: Fn<(usize,)>>(_: F) {}
fn main() {
[1, 2, 3].sort_by(|| panic!());
//~^ ERROR closure is expected to take
@ -11,9 +11,9 @@ fn main() {
[1, 2, 3].sort_by(|(tuple, tuple2): (usize, _)| panic!());
//~^ ERROR closure is expected to take
f(|| panic!());
//~^ ERROR mismatched types
//~^ ERROR closure is expected to take
f( move || panic!());
//~^ ERROR mismatched types
//~^ ERROR closure is expected to take
let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i);
//~^ ERROR closure is expected to take

View File

@ -45,33 +45,41 @@ help: change the closure to take multiple arguments instead of a single tuple
LL | [1, 2, 3].sort_by(|tuple, tuple2| panic!());
| ~~~~~~~~~~~~~~~
error[E0308]: mismatched types
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
--> $DIR/closure-arg-count.rs:13:5
|
LL | f(|| panic!());
| ^ types differ
| ^ -- takes 0 arguments
| |
| expected closure that takes 1 argument
|
= note: expected trait `Fn<usize>`
found trait `Fn<()>`
note: required by a bound in `f`
--> $DIR/closure-arg-count.rs:3:9
|
LL | fn f<F: Fn<usize>>(_: F) {}
| ^^^^^^^^^ required by this bound in `f`
LL | fn f<F: Fn<(usize,)>>(_: F) {}
| ^^^^^^^^^^^^ required by this bound in `f`
help: consider changing the closure to take and ignore the expected argument
|
LL | f(|_| panic!());
| ~~~
error[E0308]: mismatched types
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
--> $DIR/closure-arg-count.rs:15:5
|
LL | f( move || panic!());
| ^ types differ
| ^ ---------- takes 0 arguments
| |
| expected closure that takes 1 argument
|
= note: expected trait `Fn<usize>`
found trait `Fn<()>`
note: required by a bound in `f`
--> $DIR/closure-arg-count.rs:3:9
|
LL | fn f<F: Fn<usize>>(_: F) {}
| ^^^^^^^^^ required by this bound in `f`
LL | fn f<F: Fn<(usize,)>>(_: F) {}
| ^^^^^^^^^^^^ required by this bound in `f`
help: consider changing the closure to take and ignore the expected argument
|
LL | f( move |_| panic!());
| ~~~
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments
--> $DIR/closure-arg-count.rs:18:53
@ -190,5 +198,4 @@ LL | fn call<F, R>(_: F) where F: FnOnce() -> R {}
error: aborting due to 14 previous errors
Some errors have detailed explanations: E0308, E0593.
For more information about an error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0593`.