Skip to content

Most core trait impls for empty arrays are over-constrained #52246

Open
@scottmcm

Description

@scottmcm

All of the following have where T: Trait on their impls for [T; 0], but don't need it:

  • Debug
  • Copy
  • Clone
  • PartialOrd
  • Ord
  • PartialEq
  • Eq
  • Hash

A demo of those not in rustdoc:

struct Nothing;
fn must_be_copy<T: Copy>() {}
fn must_be_clone<T: Clone>() {}

pub fn empty_array_is_copy_and_clone() {
    must_be_copy::<[Nothing; 0]>();
    //^ error: the trait bound `Nothing: std::marker::Copy` is not satisfied in `[Nothing; 0]`
    must_be_clone::<[Nothing; 0]>();
    //^ error: the trait bound `Nothing: std::clone::Clone` is not satisfied in `[Nothing; 0]`
}

Kudos to whomever did the Default impls for getting this right: https://doc.rust-lang.org/std/primitive.array.html#impl-Default-29

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`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