diff --git a/impl/src/from.rs b/impl/src/from.rs index c784d972..6c6e0fee 100644 --- a/impl/src/from.rs +++ b/impl/src/from.rs @@ -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] @@ -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] @@ -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] diff --git a/tests/constructor.rs b/tests/constructor.rs index 0bda4116..1fc2834e 100644 --- a/tests/constructor.rs +++ b/tests/constructor.rs @@ -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, + } } - diff --git a/tests/deref.rs b/tests/deref.rs index 0b345541..9feab5f3 100644 --- a/tests/deref.rs +++ b/tests/deref.rs @@ -83,5 +83,7 @@ mod never { struct Tuple(!); #[derive(Deref)] - struct Struct { field: ! } + struct Struct { + field: !, + } } diff --git a/tests/from.rs b/tests/from.rs index 48f745fb..51cc6374 100644 --- a/tests/from.rs +++ b/tests/from.rs @@ -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"))] @@ -455,6 +456,20 @@ mod structs { } } } + + #[cfg(nightly)] + mod never { + use super::*; + + #[derive(From)] + struct Tuple(i32, !); + + #[derive(From)] + struct Struct { + field1: !, + field2: i16, + } + } } } @@ -1787,5 +1802,16 @@ mod enums { ); } } + + #[cfg(nightly)] + mod never { + use super::*; + + #[derive(From)] + enum Enum { + Tuple(i8, !), + Struct { field1: !, field2: i16 }, + } + } } }