Skip to content
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

Derive from any other trait only when deriving from Copy #2200

Merged
merged 1 commit into from
May 7, 2022

Conversation

vadorovsky
Copy link
Contributor

@vadorovsky vadorovsky commented May 4, 2022

It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: #2083
Signed-off-by: Michal Rostecki vadorovsky@gmail.com

@vadorovsky vadorovsky force-pushed the derive-must-copy branch 6 times, most recently from c8bc986 to 84a2ec0 Compare May 4, 2022 16:46
Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this only when the struct is packed, or what am I missing? Otherwise it might break existing code gratuitously.

@vadorovsky vadorovsky force-pushed the derive-must-copy branch 2 times, most recently from 5ba9bd2 to dea052e Compare May 4, 2022 18:03
@vadorovsky
Copy link
Contributor Author

@emilio Good point, it should be fixed now.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! I think we can simplify it slightly (given we always treat packed = None as false, but let me know if I'm missing something.

Looks good to me with that.

src/codegen/mod.rs Outdated Show resolved Hide resolved
src/codegen/mod.rs Outdated Show resolved Hide resolved
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
@vadorovsky
Copy link
Contributor Author

Thank you for review! I like the idea with using just bool without Option, I applied it.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good for now. I think this might not be fully correct in the presence of a non-packed struct containing a packed struct... For that we probably need to track this properly in the CanDerive analysis.

That shouldn't be too hard, but doing this in the meantime is fine.

@emilio emilio merged commit 4b085b4 into rust-lang:master May 7, 2022
@vadorovsky vadorovsky deleted the derive-must-copy branch May 8, 2022 10:45
@vadorovsky
Copy link
Contributor Author

@emilio Good call, I will try to address that in a separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[derive] is used on #[repr(packed)] struct that does not derive Copy (E0133)
2 participants