Skip to content

Commit

Permalink
Consider for Not
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 28, 2024
1 parent b300a0c commit 8e6bf52
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions impl/src/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions impl/src/not_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions tests/not.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

use derive_more::Not;
Expand Down Expand Up @@ -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 },
}
}

0 comments on commit 8e6bf52

Please sign in to comment.