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