KEMBAR78
trivially_copy_pass_by_ref does not consider references · Issue #2946 · rust-lang/rust-clippy · GitHub
Skip to content

trivially_copy_pass_by_ref does not consider references  #2946

@etaoins

Description

@etaoins

This code:

#[derive(Copy, Clone)]
struct OuterStruct {
    field: [u8; 8],
}

fn return_inner(outer: &OuterStruct) -> &[u8] {
    &outer.field
}

Produces:

this argument is passed by reference, but would be more efficient if passed by value

However, the outer cannot be passed by value as then it would not live long enough to return a reference to the field.

The code this was extracted from could either return a reference to the passed struct or from self. It cannot simply copy the field on return.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions