Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert_eq_size!() doesn't work with type paramenters #21

Open
orium opened this issue Oct 3, 2019 · 2 comments
Open

assert_eq_size!() doesn't work with type paramenters #21

orium opened this issue Oct 3, 2019 · 2 comments

Comments

@orium
Copy link

orium commented Oct 3, 2019

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
@LoganDark
Copy link

assert_not_impl_any! also doesn't work from inside a function, which is very annoying since negative trait bounds are not supported...

@yescallop
Copy link

yescallop commented Apr 13, 2022

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>());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants