From 8e6bf52c702cb28965181d5f3a900705a938939f Mon Sep 17 00:00:00 2001 From: tyranron Date: Wed, 28 Aug 2024 17:27:10 +0300 Subject: [PATCH] Consider for `Not` --- impl/src/from.rs | 7 ++++--- impl/src/not_like.rs | 1 + tests/not.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/impl/src/from.rs b/impl/src/from.rs index 6c6e0fee..10539ee3 100644 --- a/impl/src/from.rs +++ b/impl/src/from.rs @@ -224,9 +224,10 @@ impl<'a> Expansion<'a> { let generics = { let mut generics = self.generics.clone(); for (ty, ident) in field_tys.iter().zip(&gen_idents) { - generics.make_where_clause().predicates.push( - parse_quote! { #ty: derive_more::From<#ident> }, - ); + generics + .make_where_clause() + .predicates + .push(parse_quote! { #ty: derive_more::From<#ident> }); generics .params .push(syn::TypeParam::from(ident.clone()).into()); diff --git a/impl/src/not_like.rs b/impl/src/not_like.rs index da8a3457..40fae23f 100644 --- a/impl/src/not_like.rs +++ b/impl/src/not_like.rs @@ -35,6 +35,7 @@ pub fn expand(input: &DeriveInput, trait_name: &str) -> TokenStream { }; quote! { + #[allow(unreachable_code)] // omit warnings for `!` and other unreachable types #[automatically_derived] impl #impl_generics derive_more::#trait_ident for #input_type #ty_generics #where_clause { type Output = #output_type; diff --git a/tests/not.rs b/tests/not.rs index 96b4bb3a..31453bde 100644 --- a/tests/not.rs +++ b/tests/not.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 use derive_more::Not; @@ -27,3 +28,33 @@ enum EnumWithUnit { SmallInt(i32), Unit, } + +#[cfg(nightly)] +mod never { + use super::*; + + #[derive(Not)] + struct Tuple(!); + + #[derive(Not)] + struct Struct { + field: !, + } + + #[derive(Not)] + struct TupleMulti(i32, !); + + #[derive(Not)] + struct StructMulti { + field: !, + other: i32, + } + + #[derive(Not)] + enum Enum { + Tuple(!), + Struct { field: ! }, + TupleMulti(i32, !), + StructMulti { field: !, other: i32 }, + } +}