Skip to content

Commit

Permalink
Test Box derive for sized and unsized types
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Mar 3, 2024
1 parent ddd5f1b commit 11c07ec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/derive_box/fails/unsized_type_self_receiver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use blanket::blanket;
use impls::impls;

#[blanket(derive(Box))]
pub trait StringLike {
fn into_utf8(self) -> Vec<u8>;
}

impl StringLike for str {
fn into_utf8(self) -> Vec<u8> {
self.as_bytes().into()
}
}

fn main() {
assert!(impls!(str: StringLike));
assert!(impls!(Box<str>: StringLike));
}
12 changes: 12 additions & 0 deletions tests/derive_box/fails/unsized_type_self_receiver.stderr
Original file line number Diff line number Diff line change
@@ -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<u8> {
| ^^^^ 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<u8> {
| +
18 changes: 18 additions & 0 deletions tests/derive_box/successes/unsized_type.rs
Original file line number Diff line number Diff line change
@@ -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<str>: StringLike));
}

0 comments on commit 11c07ec

Please sign in to comment.