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

Fix merging types in multiple #[into] attributes #309

Merged
merged 5 commits into from
Oct 30, 2023

Conversation

tyranron
Copy link
Collaborator

@tyranron tyranron commented Oct 24, 2023

Synopsis

Types are not always merged correctly when multiple #[into] attributes are specified.

#[derive(Clone, Copy, Debug, Into)]
#[into(ref)]
#[into(owned)]
#[into((Wrapped<i32>, Transmuted<f32>))]
#[into(ref_mut((Wrapped<i32>, Transmuted<f32>)))]
struct Tuple(
    Wrapped<i32>,
    Wrapped<f32>,
);

expands as

#[automatically_derived]
impl ::core::convert::From<Tuple> for (Wrapped<i32>, Transmuted<f32>) {
    #[inline]
    fn from(value: Tuple) -> Self { (<Wrapped<i32> as ::core::convert::From<_>>::from(value.0), <Transmuted<f32> as ::core::convert::From<_>>::from(value.1)) }
}
#[automatically_derived]
impl<'__derive_more_into> ::core::convert::From<&'__derive_more_into Tuple> for (&'__derive_more_into Wrapped<i32>,
                                                                                 &'__derive_more_into Wrapped<f32>) {
    #[inline]
    fn from(value: &'__derive_more_into Tuple) -> Self { (<&Wrapped<i32> as ::core::convert::From<_>>::from(&value.0), <&Wrapped<f32> as ::core::convert::From<_>>::from(&value.1)) }
}
#[automatically_derived]
impl<'__derive_more_into> ::core::convert::From<&'__derive_more_into mut Tuple> for (&'__derive_more_into mut Wrapped<i32>, &'__derive_more_into mut Transmuted<f32>) {
    #[inline]
    fn from(value: &'__derive_more_into mut Tuple) -> Self { (<&mut Wrapped<i32> as ::core::convert::From<_>>::from(&mut value.0), <&mut Transmuted<f32> as ::core::convert::From<_>>::from(&mut value.1)) }
}

So, the #[into((Wrapped<i32>, Transmuted<f32>))] is totally missed in the expanded macro.

Solution

Fix merging multiple #[into(<types>)] attributes so all the specified conversions are used

Checklist

  • Documentation is updated (not required)
  • Tests are added/updated (if required)
  • CHANGELOG entry is added (not required)

@tyranron tyranron added this to the 1.0.0 milestone Oct 24, 2023
@tyranron tyranron self-assigned this Oct 24, 2023
@tyranron tyranron marked this pull request as ready for review October 24, 2023 17:58
@tyranron tyranron requested a review from JelteF October 24, 2023 18:21
@tyranron
Copy link
Collaborator Author

ping @JelteF

@tyranron tyranron merged commit ea3fbab into master Oct 30, 2023
16 checks passed
@tyranron tyranron deleted the fix-multiple-into-attrs branch October 30, 2023 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants