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

Support Self in Into derive #413

Open
nazar-pc opened this issue Sep 24, 2024 · 2 comments
Open

Support Self in Into derive #413

nazar-pc opened this issue Sep 24, 2024 · 2 comments

Comments

@nazar-pc
Copy link

#[derive(Into)]
pub struct A( [u8; Self::SIZE]);

impl A {
    const SIZE: usize = 32;
}

This generates following code:

#[allow(clippy::unused_unit)]
#[automatically_derived]
impl derive_more::core::convert::From<A> for ( [u8; Self::SIZE] ) {
    #[inline]
    fn from(value: A) -> Self { (<[u8; Self::SIZE] as derive_more::core::convert::From<_>>::from(value.0)) }
}

Which is clearly problematic because for [u8; Self::SIZE] doesn't make sense.

Self in such cases should be replaced with struct name.

@JelteF
Copy link
Owner

JelteF commented Sep 25, 2024

Seems related #335.

@teor2345
Copy link

This workaround compiles, but the struct name needs to be kept in sync:

#[derive(Into)]
pub struct A([u8; A::SIZE]);

Another workaround is to manually impl From<A> for [u8; A::SIZE].

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