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