]> git.lizzy.rs Git - rust.git/blob - tests/ui/extra_unused_lifetimes.rs
iterate List by value
[rust.git] / tests / ui / extra_unused_lifetimes.rs
1 #![allow(unused, dead_code, clippy::needless_lifetimes, clippy::needless_pass_by_value)]
2 #![warn(clippy::extra_unused_lifetimes)]
3
4 fn empty() {}
5
6 fn used_lt<'a>(x: &'a u8) {}
7
8 fn unused_lt<'a>(x: u8) {}
9
10 fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
11     // 'a is useless here since it's not directly bound
12 }
13
14 fn lt_return<'a, 'b: 'a>(x: &'b u8) -> &'a u8 {
15     panic!()
16 }
17
18 fn lt_return_only<'a>() -> &'a u8 {
19     panic!()
20 }
21
22 fn unused_lt_blergh<'a>(x: Option<Box<dyn Send + 'a>>) {}
23
24 trait Foo<'a> {
25     fn x(&self, a: &'a u8);
26 }
27
28 impl<'a> Foo<'a> for u8 {
29     fn x(&self, a: &'a u8) {}
30 }
31
32 struct Bar;
33
34 impl Bar {
35     fn x<'a>(&self) {}
36 }
37
38 // test for #489 (used lifetimes in bounds)
39 pub fn parse<'a, I: Iterator<Item = &'a str>>(_it: &mut I) {
40     unimplemented!()
41 }
42 pub fn parse2<'a, I>(_it: &mut I)
43 where
44     I: Iterator<Item = &'a str>,
45 {
46     unimplemented!()
47 }
48
49 struct X {
50     x: u32,
51 }
52
53 impl X {
54     fn self_ref_with_lifetime<'a>(&'a self) {}
55     fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
56 }
57
58 // Methods implementing traits must have matching lifetimes
59 mod issue4291 {
60     trait BadTrait {
61         fn unused_lt<'a>(x: u8) {}
62     }
63
64     impl BadTrait for () {
65         fn unused_lt<'a>(_x: u8) {}
66     }
67 }
68
69 fn main() {}