Skip to content

Commit

Permalink
Add #[allow(unreachable_code)] to Display and Debug derives
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 28, 2024
1 parent d7c4a68 commit 49dd6c3
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions impl/src/fmt/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn expand(input: &syn::DeriveInput, _: &str) -> syn::Result<TokenStream> {
};

Ok(quote! {
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
#[automatically_derived]
impl #impl_gens derive_more::Debug for #ident #ty_gens #where_clause {
#[inline]
Expand Down
1 change: 1 addition & 0 deletions impl/src/fmt/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn expand(input: &syn::DeriveInput, trait_name: &str) -> syn::Result<TokenSt
};

Ok(quote! {
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
#[automatically_derived]
impl #impl_gens derive_more::#trait_ident for #ident #ty_gens #where_clause {
fn fmt(
Expand Down
50 changes: 50 additions & 0 deletions tests/debug.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 @@ -417,6 +418,19 @@ mod structs {
}
}
}

#[cfg(nightly)]
mod never {
use derive_more::Debug;

#[derive(Debug)]
struct Tuple(!);

#[derive(Debug)]
struct Struct {
field: !,
}
}
}

mod multi_field {
Expand Down Expand Up @@ -676,6 +690,20 @@ mod structs {
);
}
}

#[cfg(nightly)]
mod never {
use derive_more::Debug;

#[derive(Debug)]
struct Tuple(i32, !);

#[derive(Debug)]
struct Struct {
field: !,
other: i32,
}
}
}
}

Expand Down Expand Up @@ -980,6 +1008,17 @@ mod enums {
}
}
}

#[cfg(nightly)]
mod never {
use derive_more::Debug;

#[derive(Debug)]
enum Enum {
Unnamed(!),
Named { field: ! },
}
}
}

mod multi_field_variant {
Expand Down Expand Up @@ -1155,6 +1194,17 @@ mod enums {
);
}
}

#[cfg(nightly)]
mod never {
use derive_more::Debug;

#[derive(Debug)]
enum Enum {
Unnamed(i32, !),
Named { field: !, other: i32 },
}
}
}
}

Expand Down
54 changes: 54 additions & 0 deletions tests/display.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 @@ -528,6 +529,19 @@ mod structs {
}
}
}

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

#[derive(Display)]
struct Tuple(!);

#[derive(Display)]
struct Struct {
field: !,
}
}
}

mod multi_field {
Expand Down Expand Up @@ -682,6 +696,22 @@ mod structs {
}
}
}

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

#[derive(Display)]
#[display("{_0}")]
struct Tuple(i32, !);

#[derive(Display)]
#[display("{field}")]
struct Struct {
field: !,
other: i32,
}
}
}
}

Expand Down Expand Up @@ -1154,6 +1184,17 @@ mod enums {
}
}
}

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

#[derive(Display)]
enum Enum {
Unnamed(!),
Named { field: ! },
}
}
}

mod multi_field_variant {
Expand Down Expand Up @@ -1314,6 +1355,19 @@ mod enums {
}
}

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

#[derive(Display)]
enum Enum {
#[display("{_0}")]
Unnamed(i32, !),
#[display("{field}")]
Named { field: !, other: i32 },
}
}

mod shared_format {
use super::*;

Expand Down

0 comments on commit 49dd6c3

Please sign in to comment.