Skip to content

Commit

Permalink
Consider for Unwrap and TryUnwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 28, 2024
1 parent 8e6bf52 commit a22d946
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions impl/src/try_unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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
1 change: 1 addition & 0 deletions impl/src/unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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
12 changes: 12 additions & 0 deletions tests/try_unwrap.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 @@ -128,3 +129,14 @@ pub fn test_try_unwrap_mut_2() {

assert_eq!(value, Tuple::Double(255, 256));
}

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

#[derive(TryUnwrap)]
enum Enum {
Tuple(!),
TupleMulti(i32, !),
}
}
12 changes: 12 additions & 0 deletions tests/unwrap.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::Unwrap;
Expand Down Expand Up @@ -117,3 +118,14 @@ pub fn test_unwrap_mut_2() {

assert_eq!(value, Tuple::Single(256));
}

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

#[derive(Unwrap)]
enum Enum {
Tuple(!),
TupleMulti(i32, !),
}
}

0 comments on commit a22d946

Please sign in to comment.