Skip to content

Commit

Permalink
Consider for Constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 28, 2024
1 parent 19c2975 commit bc4932c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions impl/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn expand(input: &DeriveInput, _: &str) -> TokenStream {
let original_types = &get_field_types(&fields);
quote! {
#[allow(missing_docs)]
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
#[automatically_derived]
impl #impl_generics #input_type #ty_generics #where_clause {
#[inline]
Expand Down
19 changes: 19 additions & 0 deletions tests/constructor.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::Constructor;
Expand Down Expand Up @@ -30,3 +31,21 @@ struct Point2D {
}

const POINT_2D: Point2D = Point2D::new(-4, 7);

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

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

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

#[derive(Constructor)]
struct TupleMulti(i32, !);

#[derive(Constructor)]
struct StructMulti { field: !, other: i32 }
}

0 comments on commit bc4932c

Please sign in to comment.