]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/functions.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / tools / clippy / 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 impl Bar {
82 fn private(self, p: *const u8) {
83 println!("{}", unsafe { *p });
84 }
85
86 pub fn public(self, p: *const u8) {
87 println!("{}", unsafe { *p });
88 println!("{:?}", unsafe { p.as_ref() });
89 unsafe { std::ptr::read(p) };
90 }
91
92 pub fn public_ok(self, p: *const u8) {
93 if !p.is_null() {
94 println!("{:p}", p);
95 }
96 }
97
98 pub unsafe fn public_unsafe(self, p: *const u8) {
99 println!("{}", unsafe { *p });
100 println!("{:?}", unsafe { p.as_ref() });
101 }
102 }
103
104 fn main() {}