Skip to content

Commit 480dcb4

Browse files
qnighycrlf0710
authored andcommitted
Add tests for boxed_closure_impls.
1 parent 059ec76 commit 480dcb4

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(boxed_closure_impls)]
2+
3+
fn call_it<T>(f: Box<dyn FnOnce() -> T>) -> T {
4+
f()
5+
}
6+
7+
fn main() {
8+
let s = "hello".to_owned();
9+
assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(fnbox)]
2+
3+
use std::boxed::FnBox;
4+
5+
fn call_it<T>(f: Box<dyn FnBox() -> T>) -> T {
6+
f()
7+
}
8+
9+
fn main() {
10+
let s = "hello".to_owned();
11+
assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(fnbox)]
2+
3+
use std::boxed::FnBox;
4+
5+
fn call_it<T>(f: Box<dyn FnBox(&i32) -> T>) -> T {
6+
f(&42)
7+
}
8+
9+
fn main() {
10+
let s = "hello".to_owned();
11+
assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
2+
--> $DIR/fnbox-compat.rs:11:34
3+
|
4+
LL | assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
5+
| ^^
6+
| |
7+
| expected closure that takes 1 argument
8+
| takes 0 arguments
9+
help: consider changing the closure to take and ignore the expected argument
10+
|
11+
LL | assert_eq!(&call_it(Box::new(|_| s)) as &str, "hello");
12+
| ^^^
13+
14+
error[E0277]: the size for values of type `dyn for<'r> std::boxed::FnBox<(&'r i32,), Output=_>` cannot be known at compilation time
15+
--> $DIR/fnbox-compat.rs:11:25
16+
|
17+
LL | assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
18+
| ^^^^^^^^ doesn't have a size known at compile-time
19+
|
20+
= help: the trait `std::marker::Sized` is not implemented for `dyn for<'r> std::boxed::FnBox<(&'r i32,), Output=_>`
21+
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
22+
= note: required by `<std::boxed::Box<T>>::new`
23+
24+
error: aborting due to 2 previous errors
25+
26+
Some errors occurred: E0277, E0593.
27+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)