static-assertions
static-assertions copied to clipboard
`assert_eq_size!()` doesn't work with type paramenters
In version 0.3 it was possible to have a assert_eq_size!()
inside a function, and refer to the type parameters of that function.
In version 1.0.0 that is no longer possible:
fn foo<T>() {
static_assertions::assert_eq_size!(Rc<T>, Arc<T>);
}
error[E0401]: can't use generic parameters from outer function
|
| fn foo<T>() {
| --- - type parameter from outer function
| |
| try adding a local generic parameter in this method instead
| static_assertions::assert_eq_size!(Rc<T>, Arc<T>);
| ^ use of generic parameter from outer function
assert_not_impl_any!
also doesn't work from inside a function, which is very annoying since negative trait bounds are not supported...
A way around this issue:
fn foo<T>() {
let _ = Assert::<Rc<T>, Arc<T>>::EQ_SIZE;
}
struct Assert<T, U> {
_marker: PhantomData<(T, U)>,
}
impl<T, U> Assert<T, U> {
const EQ_SIZE: () = assert!(mem::size_of::<T>() == mem::size_of::<U>());
}