Skip to content

Commit

Permalink
Consider for IsVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 28, 2024
1 parent 680b036 commit b300a0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions impl/src/is_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
}

let imp = quote! {
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
#[automatically_derived]
impl #imp_generics #enum_name #type_generics #where_clause {
#(#funcs)*
Expand Down
14 changes: 14 additions & 0 deletions tests/is_variant.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::IsVariant;
Expand Down Expand Up @@ -161,3 +162,16 @@ const _: () = {
assert!(!ks.is_never_mind());
assert!(ks.is_nothing_to_see_here());
};

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

#[derive(IsVariant)]
enum Enum {
Tuple(!),
Struct { field: ! },
TupleMulti(i32, !),
StructMulti { field: !, other: i32 },
}
}

0 comments on commit b300a0c

Please sign in to comment.