Skip to content

Functions in std should accept &[T; N] whenever they accept &[T] #21725

Closed
@petrochenkov

Description

@petrochenkov

Most of the time it happens automatically due to DST coercions &[T; N] => &[T], but sometimes additional care is required.

One example, where it currently doesn't work, is comparison operators between slices/arrays/vectors:

fn main() {
    let a: &[u8; 3] = &[1, 2, 3];
    let b: &[u8] = &[1, 2, 3];
    // Both comparisons doesn't compile
    a == b;
    b == a;
}

When #18465 is implemented, the code comparing byte string literals with slices will break. A lot of such code can be found, for example, in libstd/path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)A-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions