Skip to content

Commit

Permalink
Consider for From
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 28, 2024
1 parent bc4932c commit 680b036
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
3 changes: 3 additions & 0 deletions impl/src/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl<'a> Expansion<'a> {
});

Ok(quote! {
#[allow(unreachable_code)] // omit warnings for `!` and unreachable types
#[automatically_derived]
impl #impl_gens derive_more::From<#ty> for #ident #ty_gens #where_clause {
#[inline]
Expand All @@ -192,6 +193,7 @@ impl<'a> Expansion<'a> {
});

Ok(quote! {
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
#[automatically_derived]
impl #impl_gens derive_more::From<(#( #field_tys ),*)> for #ident #ty_gens #where_clause {
#[inline]
Expand Down Expand Up @@ -234,6 +236,7 @@ impl<'a> Expansion<'a> {
let (impl_gens, _, where_clause) = generics.split_for_impl();

Ok(quote! {
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
#[automatically_derived]
impl #impl_gens derive_more::From<(#( #gen_idents ),*)> for #ident #ty_gens #where_clause {
#[inline]
Expand Down
10 changes: 7 additions & 3 deletions tests/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ mod never {
struct Tuple(!);

#[derive(Constructor)]
struct Struct { field: ! }
struct Struct {
field: !,
}

#[derive(Constructor)]
struct TupleMulti(i32, !);

#[derive(Constructor)]
struct StructMulti { field: !, other: i32 }
struct StructMulti {
field: !,
other: i32,
}
}

4 changes: 3 additions & 1 deletion tests/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ mod never {
struct Tuple(!);

#[derive(Deref)]
struct Struct { field: ! }
struct Struct {
field: !,
}
}
26 changes: 26 additions & 0 deletions tests/from.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(nightly, feature(never_type))]
#![allow(dead_code)] // some code is tested for type checking only

#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -455,6 +456,20 @@ mod structs {
}
}
}

#[cfg(nightly)]
mod never {
use super::*;

#[derive(From)]
struct Tuple(i32, !);

#[derive(From)]
struct Struct {
field1: !,
field2: i16,
}
}
}
}

Expand Down Expand Up @@ -1787,5 +1802,16 @@ mod enums {
);
}
}

#[cfg(nightly)]
mod never {
use super::*;

#[derive(From)]
enum Enum {
Tuple(i8, !),
Struct { field1: !, field2: i16 },
}
}
}
}

0 comments on commit 680b036

Please sign in to comment.