[derive] Implement #[zerocopy(on_error = skip/fail)]#2982
Conversation
Summary of ChangesHello @joshlf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the flexibility of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the #[zerocopy(derive_fail_silently)] attribute, which allows derives to fail silently by not emitting an implementation instead of a compilation error. This is a valuable feature, especially for conditional compilation. The implementation is well-structured, adding a fail_silently flag to the derive context and using a helper function to conditionally suppress errors. The logic to also emit #[allow(trivial_bounds)] is correctly implemented to handle cases with unsatisfied trait bounds. The changes are applied consistently across the various derive macros. I have one suggestion to improve the test coverage for this new functionality.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2982 +/- ##
=======================================
Coverage 91.87% 91.87%
=======================================
Files 20 20
Lines 6057 6057
=======================================
Hits 5565 5565
Misses 492 492 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
#[zerocopy(derive_fail_silently)]
a5fa822 to
a584347
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the #[zerocopy(derive_fail_silently)] attribute, which allows the derive macros to suppress compilation errors and emit no implementation when requirements are not met. It also correctly adds #[allow(trivial_bounds)] when fail_silently is active, as described in the PR. The changes are consistently applied across from_bytes.rs, into_bytes.rs, try_from_bytes.rs, unaligned.rs, and util.rs, and a new test file fail_silently.rs has been added to cover the new functionality. The implementation is clean and directly addresses the stated goal.
6cb859d to
ce1dfe1
Compare
160c14e to
04ef1e5
Compare
Merge commits are not allowed on this repository
04ef1e5 to
1a18d72
Compare
#[zerocopy(derive_fail_silently)]#[zerocopy(on_error = skip/fail)]
1a18d72 to
645c197
Compare
645c197 to
ffe31b7
Compare
ffe31b7 to
465c40a
Compare
|
See also: rust-lang/rust-bindgen#3343 |
465c40a to
af4ff84
Compare
af4ff84 to
21d67e8
Compare
21d67e8 to
64e6bb9
Compare
01aac40 to
d47026e
Compare
This attribute allows deriving traits on types that do not meet requirements (e.g. missing `#[repr(C)]`) by suppressing compilation errors and emitting no implementation instead. On success, emit `#[allow(trivial_bounds)]` so that rustc permits code with unsatisfied trait bounds. For now, we're keeping this attribute experimental, requiring users to pass `--cfg zerocopy_derive_on_error` to enable it. Closes #1769 gherrit-pr-id: G4f303a34ae0677fde28c03a0e395212a3bd05ab2
d47026e to
0df5621
Compare
This attribute allows deriving traits on types that do not meet
requirements (e.g. missing
#[repr(C)]) by suppressing compilationerrors and emitting no implementation instead. On success, emit
#[allow(trivial_bounds)]so that rustc permits code with unsatisfiedtrait bounds.
For now, we're keeping this attribute experimental, requiring users to
pass
--cfg zerocopy_derive_on_errorto enable it.Closes #1769
#[zerocopy(on_error = skip/fail)]#2982Latest Update: v15 — Compare vs v14
📚 Full Patch History
Links show the diff between the row version and the column version.
⬇️ Download this PR
Branch
git fetch origin refs/heads/G4f303a34ae0677fde28c03a0e395212a3bd05ab2 && git checkout -b pr-G4f303a34ae0677fde28c03a0e395212a3bd05ab2 FETCH_HEADCheckout
git fetch origin refs/heads/G4f303a34ae0677fde28c03a0e395212a3bd05ab2 && git checkout FETCH_HEADCherry Pick
git fetch origin refs/heads/G4f303a34ae0677fde28c03a0e395212a3bd05ab2 && git cherry-pick FETCH_HEADPull
Stacked PRs enabled by GHerrit.