Skip to content

Commit

Permalink
Fix TryInto derive for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Jul 4, 2024
1 parent a429e7f commit 90c1d8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
11 changes: 10 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,12 @@ 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

0 comments on commit 90c1d8d

Please sign in to comment.