]> git.lizzy.rs Git - rust.git/blob - tests/ui/extra_unused_lifetimes.rs
Auto merge of #8720 - asquared31415:ptr-cast-ice-fix, r=Alexendoo,xFrednet
[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 mod issue6437 {
76     pub struct Scalar;
77
78     impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
79         fn add_assign(&mut self, _rhs: &Scalar) {
80             unimplemented!();
81         }
82     }
83
84     impl<'b> Scalar {
85         pub fn something<'c>() -> Self {
86             Self
87         }
88     }
89 }
90
91 // https://github.com/rust-lang/rust-clippy/pull/8737#pullrequestreview-951268213
92 mod first_case {
93     use serde::de::Visitor;
94     pub trait Expected {
95         fn fmt(&self, formatter: &mut std::fmt::Formatter);
96     }
97
98     impl<'de, T> Expected for T
99     where
100         T: Visitor<'de>,
101     {
102         fn fmt(&self, formatter: &mut std::fmt::Formatter) {}
103     }
104 }
105
106 // https://github.com/rust-lang/rust-clippy/pull/8737#pullrequestreview-951268213
107 mod second_case {
108     pub trait Source {
109         fn hey();
110     }
111
112     impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
113         fn hey() {}
114     }
115 }
116
117 fn main() {}