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 TryInto derive for generics #384

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impl/src/try_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
impl #impl_generics derive_more::core::convert::TryFrom<
#reference_with_lifetime #input_type #ty_generics
> for (#(#reference_with_lifetime #original_types),*) #where_clause {
type Error = derive_more::TryIntoError<#reference_with_lifetime #input_type>;
type Error = derive_more::TryIntoError<#reference_with_lifetime #input_type #ty_generics>;

#[inline]
fn try_from(
Expand Down
10 changes: 9 additions & 1 deletion tests/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use derive_more::{
Add, AddAssign, Constructor, Deref, DerefMut, Display, Error, From, FromStr, Index,
IndexMut, IntoIterator, Mul, MulAssign, Not, Sum,
IndexMut, IntoIterator, Mul, MulAssign, Not, Sum, TryInto,
};

#[derive(
Expand Down Expand Up @@ -262,3 +262,11 @@ struct StructLifetimeGenericBoundsConstDefault<
> {
inner: &'lt E,
}

#[derive(Debug, Display)]
struct Wrapper<'a, const Y: usize, U>(&'a [U; Y]);

#[derive(Debug, Display, TryInto)]
enum Foo<'lt: 'static, T: Clone, const X: usize> {
X(Wrapper<'lt, X, T>),
}
7 changes: 7 additions & 0 deletions tests/try_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ enum MixedInts {
Unit2,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
struct Wrapper<'a, const Y: usize, U>(&'a [U; Y]);

enum Foo<'lt: 'static, T: Clone, const X: usize> {
X(Wrapper<'lt, X, T>),
}

#[test]
fn test_try_into() {
let mut i = MixedInts::SmallInt(42);
Expand Down