assert-rs / predicates-rs

Boolean-valued predicate functions in Rust
docs.rs/predicates
Apache License 2.0
173 stars 29 forks source link

PredicateBoolean doesn't implement Predicate<T> for T: ?Sized #83

Closed asomers closed 4 years ago

asomers commented 4 years ago

I tried this code:

let p: Box<dyn Predicate<str>> = Box::new(always());

I expected to see this happen: It should compile fine

Instead this happened: Build fails with this error:

error[E0277]: the size for values of type `str` cannot be known at compilation time
  --> src/constant.rs:86:38
   |
86 |     let p: Box<dyn Predicate<str>> = Box::new(always());
   |                                      ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `str`
   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required because of the requirements on the impl of `predicates_core::core::Predicate<str>` for `constant::BooleanPredicate`
   = note: required for the cast to the object type `dyn predicates_core::core::Predicate<str>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

Meta

predicates-rs version: 1.0.1 rustc --version --verbose:

> rustc --version --verbose
rustc 1.41.0-nightly (1bd30ce2a 2019-11-15)
binary: rustc
commit-hash: 1bd30ce2aac40c7698aa4a1b9520aa649ff2d1c5
commit-date: 2019-11-15
host: x86_64-unknown-freebsd
release: 1.41.0-nightly
LLVM version: 9.0

Originally reported at https://github.com/asomers/mockall/issues/78