Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivially_copy_pass_by_ref does not consider references #2946

Closed
etaoins opened this issue Jul 21, 2018 · 1 comment
Closed

trivially_copy_pass_by_ref does not consider references #2946

etaoins opened this issue Jul 21, 2018 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@etaoins
Copy link
Contributor

etaoins commented Jul 21, 2018

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.

@flip1995 flip1995 added the C-bug Category: Clippy is not doing the correct thing label Jul 21, 2018
@etaoins
Copy link
Contributor Author

etaoins commented Jul 21, 2018

This case might be fixable by suppressing the lint if the argument lifetime equals the return lifetime. I'll take a look once the build is working again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants