rust-clippy/tests/ui/extra_unused_lifetimes.rs

70 lines
1.2 KiB
Rust
Raw Normal View History

2020-04-08 14:00:03 +00:00
#![allow(unused, dead_code, clippy::needless_lifetimes, clippy::needless_pass_by_value)]
2018-07-28 15:34:52 +00:00
#![warn(clippy::extra_unused_lifetimes)]
2018-12-09 22:26:16 +00:00
fn empty() {}
2018-12-09 22:26:16 +00:00
fn used_lt<'a>(x: &'a u8) {}
2018-12-09 22:26:16 +00:00
fn unused_lt<'a>(x: u8) {}
2017-02-08 13:58:07 +00:00
fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
// 'a is useless here since it's not directly bound
}
fn lt_return<'a, 'b: 'a>(x: &'b u8) -> &'a u8 {
panic!()
}
fn lt_return_only<'a>() -> &'a u8 {
panic!()
}
fn unused_lt_blergh<'a>(x: Option<Box<dyn Send + 'a>>) {}
trait Foo<'a> {
fn x(&self, a: &'a u8);
}
impl<'a> Foo<'a> for u8 {
2018-12-09 22:26:16 +00:00
fn x(&self, a: &'a u8) {}
}
struct Bar;
impl Bar {
2017-02-08 13:58:07 +00:00
fn x<'a>(&self) {}
}
// test for #489 (used lifetimes in bounds)
2018-12-09 22:26:16 +00:00
pub fn parse<'a, I: Iterator<Item = &'a str>>(_it: &mut I) {
unimplemented!()
}
2018-12-09 22:26:16 +00:00
pub fn parse2<'a, I>(_it: &mut I)
where
I: Iterator<Item = &'a str>,
{
unimplemented!()
}
2018-12-09 22:26:16 +00:00
struct X {
x: u32,
}
impl X {
fn self_ref_with_lifetime<'a>(&'a self) {}
fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
}
// Methods implementing traits must have matching lifetimes
mod issue4291 {
2019-09-01 05:55:29 +00:00
trait BadTrait {
fn unused_lt<'a>(x: u8) {}
}
2019-09-01 05:55:29 +00:00
impl BadTrait for () {
fn unused_lt<'a>(_x: u8) {}
}
}
2018-12-09 22:26:16 +00:00
fn main() {}