Skip to content

Use const generics for array Default impl #61415

Open

Description

Currently, we generate array impls for every size up to 32 manually using macros, but with const generics at a suitable level of implementation, we can switch to properly parameterising over all lengths.

  • Replace most manual impls with const generic impls (PR: Use const generics for array impls [part 1] #62435)
  • Replace Default impl with const generic impl (more difficult due to Switch libcore array implementations to const generics. #60466 (comment)).
  • Reimplement impls removed due to bloat using const generic impls (see

    rust/src/libcore/array.rs

    Lines 221 to 227 in 7840a0b

    // NOTE: some less important impls are omitted to reduce code bloat
    __impl_slice_eq1! { [A; $N], [B; $N] }
    __impl_slice_eq2! { [A; $N], [B] }
    __impl_slice_eq2! { [A; $N], &'b [B] }
    __impl_slice_eq2! { [A; $N], &'b mut [B] }
    // __impl_slice_eq2! { [A; $N], &'b [B; $N] }
    // __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
    and

    rust/src/liballoc/vec.rs

    Lines 2199 to 2204 in bfdfa85

    // NOTE: some less important impls are omitted to reduce code bloat
    // FIXME(Centril): Reconsider this?
    //__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], [B; N]: LengthAtMost32 }
    //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], [B; N]: LengthAtMost32 }
    //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], [B; N]: LengthAtMost32 }
    //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], [B; N]: LengthAtMost32 }
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`A-const-genericsArea: const generics (parameters and arguments)A-sliceArea: `[T]`Libs-TrackedLibs issues that are tracked on the team's project board.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions