Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: google/zerocopy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.8.12
Choose a base ref
...
head repository: google/zerocopy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.8.13
Choose a head ref
  • 2 commits
  • 7 files changed
  • 2 contributors

Commits on Dec 4, 2024

  1. Practice good Self hygiene (#2127)

    This commit revises the `KnownLayout` derive on `repr(C)` target structs to
    preserve the correct resolution of `Self` when constructing
    `__ZerocopyKnownLayoutMaybeUninit`. This type contains a `MaybeUninit` version
    of each of the target struct's field types. Previously, it achieved this by
    simply copying the tokens corresponding to field types from the definition of
    the target struct into the definition of `__ZerocopyKnownLayoutMaybeUninit`
    
    However, on types like this:
    
        #[repr(C)]
        struct Struct([u8; Self::N]);
    
    …this approach is insufficient. Pasted into `__ZerocopyKnownLayoutMaybeUninit`,
    `Self` ceases to refer to the target struct and instead refers to
    `__ZerocopyKnownLayoutMaybeUninit`.
    
    To preserve `Self` hygiene, this commit defines a struct for projecting the
    field types of the target struct based on their index:
    
        pub unsafe trait Field<Index> {
            type Type: ?Sized;
        }
    
    …then implements it for each of the field types of the target struct; e.g.:
    
        struct Index<const N: usize>;
    
        impl Field<Index<0>> for Struct {
            type Type = [u8; Self::N];
        }
    
    With this, the fields of `__ZerocopyKnownLayoutMaybeUninit` can be defined
    hygienically; e.g., as `<Struct as Field<0>>::Type`.
    
    Fixes #2116
    jswrenn authored Dec 4, 2024
    Configuration menu
    Copy the full SHA
    f436922 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2c8ef74 View commit details
    Browse the repository at this point in the history
Loading