]> git.lizzy.rs Git - rust.git/blob - tests/ui/functions.rs
Apply `not_unsafe_ptr_arg_deref` to type aliases
[rust.git] / tests / ui / functions.rs
1 #![warn(clippy::all)]
2 #![allow(dead_code)]
3 #![allow(unused_unsafe, clippy::missing_safety_doc)]
4
5 // TOO_MANY_ARGUMENTS
6 fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
7
8 fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
9
10 #[rustfmt::skip]
11 fn bad_multiline(
12     one: u32,
13     two: u32,
14     three: &str,
15     four: bool,
16     five: f32,
17     six: f32,
18     seven: bool,
19     eight: ()
20 ) {
21     let _one = one;
22     let _two = two;
23     let _three = three;
24     let _four = four;
25     let _five = five;
26     let _six = six;
27     let _seven = seven;
28 }
29
30 // don't lint extern fns
31 extern "C" fn extern_fn(
32     _one: u32,
33     _two: u32,
34     _three: *const u8,
35     _four: bool,
36     _five: f32,
37     _six: f32,
38     _seven: bool,
39     _eight: *const std::ffi::c_void,
40 ) {
41 }
42
43 pub trait Foo {
44     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
45     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());
46
47     fn ptr(p: *const u8);
48 }
49
50 pub struct Bar;
51
52 impl Bar {
53     fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
54     fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
55 }
56
57 // ok, we don’t want to warn implementations
58 impl Foo for Bar {
59     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
60     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
61
62     fn ptr(p: *const u8) {
63         println!("{}", unsafe { *p });
64         println!("{:?}", unsafe { p.as_ref() });
65         unsafe { std::ptr::read(p) };
66     }
67 }
68
69 // NOT_UNSAFE_PTR_ARG_DEREF
70
71 fn private(p: *const u8) {
72     println!("{}", unsafe { *p });
73 }
74
75 pub fn public(p: *const u8) {
76     println!("{}", unsafe { *p });
77     println!("{:?}", unsafe { p.as_ref() });
78     unsafe { std::ptr::read(p) };
79 }
80
81 type Alias = *const u8;
82
83 pub fn type_alias(p: Alias) {
84     println!("{}", unsafe { *p });
85     println!("{:?}", unsafe { p.as_ref() });
86     unsafe { std::ptr::read(p) };
87 }
88
89 impl Bar {
90     fn private(self, p: *const u8) {
91         println!("{}", unsafe { *p });
92     }
93
94     pub fn public(self, p: *const u8) {
95         println!("{}", unsafe { *p });
96         println!("{:?}", unsafe { p.as_ref() });
97         unsafe { std::ptr::read(p) };
98     }
99
100     pub fn public_ok(self, p: *const u8) {
101         if !p.is_null() {
102             println!("{:p}", p);
103         }
104     }
105
106     pub unsafe fn public_unsafe(self, p: *const u8) {
107         println!("{}", unsafe { *p });
108         println!("{:?}", unsafe { p.as_ref() });
109     }
110 }
111
112 fn main() {}