]> git.lizzy.rs Git - rust.git/blob - tests/ui/functions.rs
Merge pull request #3265 from mikerite/fix-export
[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
11 #![feature(tool_lints)]
12
13
14 #![warn(clippy::all)]
15 #![allow(dead_code)]
16 #![allow(unused_unsafe)]
17
18 // TOO_MANY_ARGUMENTS
19 fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
20
21 fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {
22 }
23
24 // don't lint extern fns
25 extern fn extern_fn(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
26
27 pub trait Foo {
28     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
29     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());
30
31     fn ptr(p: *const u8);
32 }
33
34 pub struct Bar;
35
36 impl Bar {
37     fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
38     fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
39 }
40
41 // ok, we don’t want to warn implementations
42 impl Foo for Bar {
43     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
44     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
45
46     fn ptr(p: *const u8) {
47         println!("{}", unsafe { *p });
48         println!("{:?}", unsafe { p.as_ref() });
49         unsafe { std::ptr::read(p) };
50     }
51 }
52
53 // NOT_UNSAFE_PTR_ARG_DEREF
54
55 fn private(p: *const u8) {
56     println!("{}", unsafe { *p });
57 }
58
59 pub fn public(p: *const u8) {
60     println!("{}", unsafe { *p });
61     println!("{:?}", unsafe { p.as_ref() });
62     unsafe { std::ptr::read(p) };
63 }
64
65 impl Bar {
66     fn private(self, p: *const u8) {
67         println!("{}", unsafe { *p });
68     }
69
70     pub fn public(self, p: *const u8) {
71         println!("{}", unsafe { *p });
72         println!("{:?}", unsafe { p.as_ref() });
73         unsafe { std::ptr::read(p) };
74     }
75
76     pub fn public_ok(self, p: *const u8) {
77         if !p.is_null() {
78             println!("{:p}", p);
79         }
80     }
81
82     pub unsafe fn public_unsafe(self, p: *const u8) {
83         println!("{}", unsafe { *p });
84         println!("{:?}", unsafe { p.as_ref() });
85     }
86 }
87
88 fn main() {}