From 480dcb403caa90ecd2cc717ad4801805c010d3f6 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Sun, 28 Oct 2018 15:28:47 +0900 Subject: [PATCH] Add tests for boxed_closure_impls. --- .../run-pass/unsized-locals/box-fnonce.rs | 10 +++++++ .../run-pass/unsized-locals/fnbox-compat.rs | 12 +++++++++ src/test/ui/unsized-locals/fnbox-compat.rs | 12 +++++++++ .../ui/unsized-locals/fnbox-compat.stderr | 27 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 src/test/run-pass/unsized-locals/box-fnonce.rs create mode 100644 src/test/run-pass/unsized-locals/fnbox-compat.rs create mode 100644 src/test/ui/unsized-locals/fnbox-compat.rs create mode 100644 src/test/ui/unsized-locals/fnbox-compat.stderr diff --git a/src/test/run-pass/unsized-locals/box-fnonce.rs b/src/test/run-pass/unsized-locals/box-fnonce.rs new file mode 100644 index 00000000000..97007a94239 --- /dev/null +++ b/src/test/run-pass/unsized-locals/box-fnonce.rs @@ -0,0 +1,10 @@ +#![feature(boxed_closure_impls)] + +fn call_it(f: Box T>) -> T { + f() +} + +fn main() { + let s = "hello".to_owned(); + assert_eq!(&call_it(Box::new(|| s)) as &str, "hello"); +} diff --git a/src/test/run-pass/unsized-locals/fnbox-compat.rs b/src/test/run-pass/unsized-locals/fnbox-compat.rs new file mode 100644 index 00000000000..5ec54ada13b --- /dev/null +++ b/src/test/run-pass/unsized-locals/fnbox-compat.rs @@ -0,0 +1,12 @@ +#![feature(fnbox)] + +use std::boxed::FnBox; + +fn call_it(f: Box T>) -> T { + f() +} + +fn main() { + let s = "hello".to_owned(); + assert_eq!(&call_it(Box::new(|| s)) as &str, "hello"); +} diff --git a/src/test/ui/unsized-locals/fnbox-compat.rs b/src/test/ui/unsized-locals/fnbox-compat.rs new file mode 100644 index 00000000000..3cb9ac560a2 --- /dev/null +++ b/src/test/ui/unsized-locals/fnbox-compat.rs @@ -0,0 +1,12 @@ +#![feature(fnbox)] + +use std::boxed::FnBox; + +fn call_it(f: Box T>) -> T { + f(&42) +} + +fn main() { + let s = "hello".to_owned(); + assert_eq!(&call_it(Box::new(|| s)) as &str, "hello"); +} diff --git a/src/test/ui/unsized-locals/fnbox-compat.stderr b/src/test/ui/unsized-locals/fnbox-compat.stderr new file mode 100644 index 00000000000..5172092fb1c --- /dev/null +++ b/src/test/ui/unsized-locals/fnbox-compat.stderr @@ -0,0 +1,27 @@ +error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments + --> $DIR/fnbox-compat.rs:11:34 + | +LL | assert_eq!(&call_it(Box::new(|| s)) as &str, "hello"); + | ^^ + | | + | expected closure that takes 1 argument + | takes 0 arguments +help: consider changing the closure to take and ignore the expected argument + | +LL | assert_eq!(&call_it(Box::new(|_| s)) as &str, "hello"); + | ^^^ + +error[E0277]: the size for values of type `dyn for<'r> std::boxed::FnBox<(&'r i32,), Output=_>` cannot be known at compilation time + --> $DIR/fnbox-compat.rs:11:25 + | +LL | assert_eq!(&call_it(Box::new(|| s)) as &str, "hello"); + | ^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `dyn for<'r> std::boxed::FnBox<(&'r i32,), Output=_>` + = note: to learn more, visit + = note: required by `>::new` + +error: aborting due to 2 previous errors + +Some errors occurred: E0277, E0593. +For more information about an error, try `rustc --explain E0277`.