Skip to content

Suggest usage of array.as_slice() (instead of &array[..]) and array.as_mut_slice() #7633

Description

@Luro02

What it does

Lints for example this code:

let array: [u8; 4] = [1, 2, 3, 4];
let slice: &[u8] = &array[..];

and suggests array::as_slice:

let array: [u8; 4] = [1, 2, 3, 4];
let slice: &[u8] = array.as_slice();

(same should be suggested for &mut array[..], which can be replaced with array.as_mut_slice())

Categories (optional)

  • Kind: clippy::pedantic or clippy::style

What is the advantage of the recommended code over the original code?

For example:

Drawbacks

  • might have a lot of false positives or not much benefit in using the function

Possibly related issues:

Stabilization

At the time of writing this issue, the function is still unstable, but with the merging of rust-lang/rust#88353, this feature will be stabilized. (final-comment-period, so will be merged in the next few days)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsL-restrictionLint: Belongs in the restriction lint groupgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions