Open
Description
I've encountered a false positive with the trivially_copy_pass_by_ref lint. While Clippy is able to tell that a function takes a &u8
instead of a u8
, it doesn't seem to be checking whether that reference is passed to another function that requires a reference rather than a value. My example:
// Clippy says:
// error: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
pub fn contains(&self, target: &u8) -> bool {
exists_within(some_bytes, target)
}
pub fn exists_within<'a, T>(slice: &'a [T], reference: &'a T) -> bool {
unimplemented!()
}
Its recommended fix (to change it to a u8
) won't work here, because the function the reference is passed to requires it to be a reference.
I made a quick Rust playground with the exact code that ran into this issue.
Thanks for Clippy!
$ cargo clippy -V
clippy 0.0.212 (204bb9b5 2020-03-17)
Metadata
Metadata
Assignees
Labels
Category: Clippy is not doing the correct thingCall for participation: This a hard problem and requires more experience or effort to work onIssue: The lint was triggered on code it shouldn't haveIssue: The suggestions provided by this Lint cause an ICE/error when appliedStatus: Needs further discussion before merging or work can be started