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

compiler: allow transmute of ZST arrays with generics #114009

Merged
merged 1 commit into from
Mar 23, 2024

Commits on Mar 20, 2024

  1. compiler: allow transmute of ZST arrays with generics

    Extend the `SizeSkeleton` evaluator to shortcut zero-sized arrays, thus
    considering `[T; 0]` to have a compile-time fixed-size of 0.
    
    The existing evaluator already deals with generic arrays under the
    feature-guard `transmute_const_generics`. However, it merely allows
    comparing fixed-size types with fixed-size types, and generic types with
    generic types. For generic types, it merely compares whether their
    arguments match (ordering them first). Even if their exact sizes are not
    known at compile time, it can ensure that they will eventually be the
    same.
    
    This patch extends this by shortcutting the size-evaluation of zero
    sized arrays and thus allowing size comparisons of `()` with `[T; 0]`,
    where one contains generics and the other does not.
    
    This code is guarded by `transmute_const_generics` (rust-lang#109929), even
    though it is unclear whether it should be. However, this assumes that a
    separate stabilization PR is required to move this out of the feature
    guard.
    
    Initially reported in rust-lang#98104.
    dvdhrm committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    31d23c4 View commit details
    Browse the repository at this point in the history