]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/should_impl_trait/corner_cases.rs
Rollup merge of #78769 - est31:remove_lifetimes, r=KodrAus
[rust.git] / src / tools / clippy / tests / ui / should_impl_trait / corner_cases.rs
1 // edition:2018
2
3 #![warn(clippy::all, clippy::pedantic)]
4 #![allow(
5     clippy::missing_errors_doc,
6     clippy::needless_pass_by_value,
7     clippy::must_use_candidate,
8     clippy::unused_self,
9     clippy::needless_lifetimes,
10     clippy::missing_safety_doc,
11     clippy::wrong_self_convention
12 )]
13
14 use std::ops::Mul;
15 use std::rc::{self, Rc};
16 use std::sync::{self, Arc};
17
18 fn main() {}
19
20 pub struct T1;
21 impl T1 {
22     // corner cases: should not lint
23
24     // no error, not public interface
25     pub(crate) fn drop(&mut self) {}
26
27     // no error, private function
28     fn neg(self) -> Self {
29         self
30     }
31
32     // no error, private function
33     fn eq(&self, other: Self) -> bool {
34         true
35     }
36
37     // No error; self is a ref.
38     fn sub(&self, other: Self) -> &Self {
39         self
40     }
41
42     // No error; different number of arguments.
43     fn div(self) -> Self {
44         self
45     }
46
47     // No error; wrong return type.
48     fn rem(self, other: Self) {}
49
50     // Fine
51     fn into_u32(self) -> u32 {
52         0
53     }
54
55     fn into_u16(&self) -> u16 {
56         0
57     }
58
59     fn to_something(self) -> u32 {
60         0
61     }
62
63     fn new(self) -> Self {
64         unimplemented!();
65     }
66
67     pub fn next<'b>(&'b mut self) -> Option<&'b mut T1> {
68         unimplemented!();
69     }
70 }
71
72 pub struct T2;
73 impl T2 {
74     // Shouldn't trigger lint as it is unsafe.
75     pub unsafe fn add(self, rhs: Self) -> Self {
76         self
77     }
78
79     // Should not trigger lint since this is an async function.
80     pub async fn next(&mut self) -> Option<Self> {
81         None
82     }
83 }