]> git.lizzy.rs Git - rust.git/blob - tests/ui/functions.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / functions.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::all)]
11 #![allow(dead_code)]
12 #![allow(unused_unsafe)]
13
14 // TOO_MANY_ARGUMENTS
15 fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
16
17 fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
18
19 // don't lint extern fns
20 extern "C" fn extern_fn(
21     _one: u32,
22     _two: u32,
23     _three: &str,
24     _four: bool,
25     _five: f32,
26     _six: f32,
27     _seven: bool,
28     _eight: (),
29 ) {
30 }
31
32 pub trait Foo {
33     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
34     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());
35
36     fn ptr(p: *const u8);
37 }
38
39 pub struct Bar;
40
41 impl Bar {
42     fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
43     fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
44 }
45
46 // ok, we don’t want to warn implementations
47 impl Foo for Bar {
48     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
49     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
50
51     fn ptr(p: *const u8) {
52         println!("{}", unsafe { *p });
53         println!("{:?}", unsafe { p.as_ref() });
54         unsafe { std::ptr::read(p) };
55     }
56 }
57
58 // NOT_UNSAFE_PTR_ARG_DEREF
59
60 fn private(p: *const u8) {
61     println!("{}", unsafe { *p });
62 }
63
64 pub fn public(p: *const u8) {
65     println!("{}", unsafe { *p });
66     println!("{:?}", unsafe { p.as_ref() });
67     unsafe { std::ptr::read(p) };
68 }
69
70 impl Bar {
71     fn private(self, p: *const u8) {
72         println!("{}", unsafe { *p });
73     }
74
75     pub fn public(self, p: *const u8) {
76         println!("{}", unsafe { *p });
77         println!("{:?}", unsafe { p.as_ref() });
78         unsafe { std::ptr::read(p) };
79     }
80
81     pub fn public_ok(self, p: *const u8) {
82         if !p.is_null() {
83             println!("{:p}", p);
84         }
85     }
86
87     pub unsafe fn public_unsafe(self, p: *const u8) {
88         println!("{}", unsafe { *p });
89         println!("{:?}", unsafe { p.as_ref() });
90     }
91 }
92
93 fn main() {}