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] Overhaul repr parsing #1752

Merged
merged 1 commit into from
Sep 30, 2024
Merged

[derive] Overhaul repr parsing #1752

merged 1 commit into from
Sep 30, 2024

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Sep 25, 2024

Represent the result of parsing all #[repr(...)] attributes on a type as a high-level type which is only capable of representing valid combinations of #[repr(...)] attributes and processes them into a concise representation that's easier for high-level code to work with.

This prepares us to more easily fix #1748.

While we're here, we make a number of other improvements.

  1. Errors are now converted to TokenStreams as late as possible rather than as early as possible, which was the previous behavior. This allows us to bail early when deriving an implied trait fails (e.g., deriving TryFromBytes when the user wrote #[derive(FromZeros)]).
  2. Avoid re-computing some repr information in TryFromBytes enum support.

zerocopy-derive/tests/ui-msrv/enum.stderr Outdated Show resolved Hide resolved
zerocopy-derive/src/enum.rs Show resolved Hide resolved
@joshlf joshlf marked this pull request as ready for review September 26, 2024 01:57
@joshlf joshlf force-pushed the derive-repr-overhaul branch 2 times, most recently from 2148b46 to fa664c3 Compare September 26, 2024 13:43
zerocopy-derive/src/lib.rs Show resolved Hide resolved
zerocopy-derive/src/lib.rs Outdated Show resolved Hide resolved
zerocopy-derive/src/lib.rs Outdated Show resolved Hide resolved
zerocopy-derive/src/repr.rs Show resolved Hide resolved
zerocopy-derive/src/repr.rs Outdated Show resolved Hide resolved
zerocopy-derive/src/repr.rs Show resolved Hide resolved
@joshlf joshlf force-pushed the derive-repr-overhaul branch 7 times, most recently from d806d1a to cc2acfe Compare September 26, 2024 20:23
Represent the result of parsing all `#[repr(...)]` attributes on a type
as a high-level type which is only capable of representing valid
combinations of `#[repr(...)]` attributes and processes them into a
concise representation that's easier for high-level code to work with.

This prepares us to more easily fix #1748.

While we're here, we make a number of other improvements.

1) Errors are now converted to `TokenStream`s as late as possible rather
   than as early as possible, which was the previous behavior. This
   allows us to bail early when deriving an implied trait fails (e.g.,
   deriving `TryFromBytes` when the user wrote `#[derive(FromZeros)]`).
2) Avoid re-computing some repr information in `TryFromBytes` enum
   support.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.46%. Comparing base (6b7a012) to head (a5ebe1a).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1752   +/-   ##
=======================================
  Coverage   87.46%   87.46%           
=======================================
  Files          16       16           
  Lines        6021     6021           
=======================================
  Hits         5266     5266           
  Misses        755      755           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

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

Reviewed over video call.

@joshlf joshlf dismissed djkoloski’s stale review September 30, 2024 18:57

Addressed all feedback; re-reviewed by @jswrenn

@joshlf joshlf added this pull request to the merge queue Sep 30, 2024
Merged via the queue into main with commit 8e0de3f Sep 30, 2024
86 checks passed
@joshlf joshlf deleted the derive-repr-overhaul branch September 30, 2024 19:22
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.

Soundness hole in #[derive(IntoBytes)] on types with #[repr(align)]
4 participants