-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
suppress_derive_clone
struct attribute
This attribute suppresses the default-generated `derive(Clone)`. This may be necessary where `derive(Clone)` copies constraints in an unsatisfiable way. See: https://smallcultfollowing.com/babysteps//blog/2022/04/12/implied-bounds-and-perfect-derive/ See: rust-lang/rust#26925 Fixes: #325
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
derive_builder/tests/compile-fail/suppress_derive_clone.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[macro_use] | ||
extern crate derive_builder; | ||
|
||
#[derive(Builder)] | ||
#[builder(suppress_derive_clone)] | ||
pub struct Example { | ||
field: String, | ||
} | ||
|
||
fn main() { | ||
let _ = LoremBuilder::default().clone(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#[macro_use] | ||
extern crate derive_builder; | ||
|
||
#[derive(Debug, Builder, PartialEq, Clone)] | ||
#[builder(suppress_derive_clone)] | ||
struct Lorem { | ||
#[builder(setter(into))] | ||
ipsum: String, | ||
} | ||
|
||
impl Clone for LoremBuilder { | ||
fn clone(&self) -> Self { | ||
Self { | ||
ipsum: self.ipsum.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn error_if_uninitialized() { | ||
let error = LoremBuilder::default().build().unwrap_err(); | ||
assert_eq!(&error.to_string(), "`ipsum` must be initialized"); | ||
} | ||
|
||
#[test] | ||
fn builder_test() { | ||
let x = LoremBuilder::default().ipsum("ipsum").build().unwrap(); | ||
|
||
assert_eq!( | ||
x, | ||
Lorem { | ||
ipsum: "ipsum".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn builder_is_clone() { | ||
let _ = LoremBuilder::default().clone(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters