Lifetime could be elided in the trait, but Clippy didn't notice that. Please add correction to clippy so that it warns about it and suggests to elide it
Lint Name
needless_lifetimes
Reproducer
I tried this code (copy+paste into main() function):
#[derive(Debug)]
pub enum Key<'a> {
Ref(&'a [u8]),
Val8([u8; 1]),
Val16([u8; 2]),
Val32([u8; 4]),
Val64([u8; 8]),
Val128([u8; 16]),
}
impl<'a> AsRef<[u8]> for Key<'a> {
fn as_ref(&self) -> &[u8] {
match self {
Key::Ref(r) => r,
Key::Val8(v) => v,
Key::Val16(v) => v,
Key::Val32(v) => v,
Key::Val64(v) => v,
Key::Val128(v) => v,
}
}
}
pub trait Prefixer<'a> {
/// returns 0 or more namespaces that should be length-prefixed and concatenated for range searches
fn prefix(&self) -> Vec<Key>;
// fn joined_prefix(&self) -> Vec<u8> {
// let prefixes = self.prefix();
// namespaces_with_key(&prefixes.iter().map(Key::as_ref).collect::<Vec<_>>(), &[])
// }
}
impl<'a> Prefixer<'a> for Vec<u8> {
fn prefix(&self) -> Vec<Key> {
vec![Key::Ref(self.as_ref())]
}
}
I expected to see this happen:
Clippy should warn about this paragraph:
Note that the changes are in the first line of the quoted paragraph, and particularly the lifetime parameters being simplified from two instances of <'a> into just one instance of <'_>
Instead, this happened:
clippy had nothing to say about this code
Summary
Lifetime could be elided in the trait, but Clippy didn't notice that. Please add correction to clippy so that it warns about it and suggests to elide it
Lint Name
needless_lifetimes
Reproducer
I tried this code (copy+paste into main() function):
I expected to see this happen: Clippy should warn about this paragraph:
Clippy should suggest to replace it with the following:
Note that the changes are in the first line of the quoted paragraph, and particularly the lifetime parameters being simplified from two instances of
<'a>
into just one instance of<'_>
Instead, this happened: clippy had nothing to say about this code
Version