-
Notifications
You must be signed in to change notification settings - Fork 165
Feat: Add debug/copy derives and enable missing debug/copy lint #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add debug/copy derives and enable missing debug/copy lint #228
Conversation
Co-authored-by: Fernando Otero <[email protected]>
Co-authored-by: Fernando Otero <[email protected]>
Co-authored-by: Fernando Otero <[email protected]>
Co-authored-by: Fernando Otero <[email protected]>
Co-authored-by: Fernando Otero <[email protected]>
Co-authored-by: Fernando Otero <[email protected]>
Co-authored-by: Fernando Otero <[email protected]>
febo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
|
Is it a good idea to derive Here, a move happens, so I don't really want to bother to use reference. |
This is a good point. Perhaps would be prudent to not implement |
|
I still think if a type can be copy it probably should (which is what the std docs say as well). I'd imagine the compiler would probably optimize any unnecessary copies out anyway, although that would perhaps be worth benchmarking. If you really don't want the type to be copy, you could always make a newtype wrapper around the struct and not impl copy on that. #[derive(Clone)]
#[repr(transparent)]
pub struct RentNoCopy(Rent);Having it copy allows more choices. In star frame, we plop sysvars in a Cell, which is only possible since they're copy: https://github.com/staratlasmeta/star_frame/blob/eb1d9f8b8a3a10e88bfc08bd459433881cce56b6/star_frame/src/context.rs#L17 |
Yeah, that is also a good point. 😊 Given that it is possible to go from |
|
The advice to implement |
This is probable the best compromise. |
Types that can implement copy generally should: https://doc.rust-lang.org/std/marker/trait.Copy.html#when-should-my-type-be-copy
For debug, the rust API guidelines suggest debug should always be implemented in public types: https://rust-lang.github.io/api-guidelines/debuggability.html#all-public-types-implement-debug-c-debug