From 11c07ec06b40127098ca4c041a432a5cced6574a Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Sun, 3 Mar 2024 22:46:34 +0100 Subject: [PATCH] Test `Box` derive for sized and unsized types --- .../fails/unsized_type_self_receiver.rs | 18 ++++++++++++++++++ .../fails/unsized_type_self_receiver.stderr | 12 ++++++++++++ tests/derive_box/successes/unsized_type.rs | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/derive_box/fails/unsized_type_self_receiver.rs create mode 100644 tests/derive_box/fails/unsized_type_self_receiver.stderr create mode 100644 tests/derive_box/successes/unsized_type.rs diff --git a/tests/derive_box/fails/unsized_type_self_receiver.rs b/tests/derive_box/fails/unsized_type_self_receiver.rs new file mode 100644 index 0000000..a2095c9 --- /dev/null +++ b/tests/derive_box/fails/unsized_type_self_receiver.rs @@ -0,0 +1,18 @@ +use blanket::blanket; +use impls::impls; + +#[blanket(derive(Box))] +pub trait StringLike { + fn into_utf8(self) -> Vec; +} + +impl StringLike for str { + fn into_utf8(self) -> Vec { + self.as_bytes().into() + } +} + +fn main() { + assert!(impls!(str: StringLike)); + assert!(impls!(Box: StringLike)); +} diff --git a/tests/derive_box/fails/unsized_type_self_receiver.stderr b/tests/derive_box/fails/unsized_type_self_receiver.stderr new file mode 100644 index 0000000..e3c5208 --- /dev/null +++ b/tests/derive_box/fails/unsized_type_self_receiver.stderr @@ -0,0 +1,12 @@ +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> tests/derive_box/fails/unsized_type_self_receiver.rs:10:18 + | +10 | fn into_utf8(self) -> Vec { + | ^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +10 | fn into_utf8(&self) -> Vec { + | + diff --git a/tests/derive_box/successes/unsized_type.rs b/tests/derive_box/successes/unsized_type.rs new file mode 100644 index 0000000..ee8d180 --- /dev/null +++ b/tests/derive_box/successes/unsized_type.rs @@ -0,0 +1,18 @@ +use blanket::blanket; +use impls::impls; + +#[blanket(derive(Box))] +pub trait StringLike { + fn is_utf8(&self) -> bool; +} + +impl StringLike for str { + fn is_utf8(&self) -> bool { + true + } +} + +fn main() { + assert!(impls!(str: StringLike)); + assert!(impls!(Box: StringLike)); +}