Skip to content

[ER] Unused lifetime warning #91588

Open
Open
@leonardo-m

Description

@leonardo-m

In code like this rustc could warn that the 'b lifetime is not needed:

fn select<'a, 'b, const N: usize>(data: &'a mut [u32; N],
                                  keep: &'b mut [bool; N]) -> &'a [u32] {
    let mut pos = 0;
    for (i, &b) in keep.iter().enumerate() {
        if b {
            data[pos] = data[i];
            pos += 1;
        }
    }
    &data[.. pos]
}

fn main() {
    let mut data = [1, 2, 3, 4, 5];
    let mut keep = [true, false, true, false, true];
    println!("{:?}", select(&mut data, &mut keep));
}

(Currently rustc also doesn't spot that the 'keep' function argument doesn't need to be &mut).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions