]> git.lizzy.rs Git - rust.git/blob - tests/ui/functions.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / functions.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(clippy)]
5 #![allow(dead_code)]
6 #![allow(unused_unsafe)]
7
8 // TOO_MANY_ARGUMENTS
9 fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
10
11 fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {
12     //~^ ERROR: this function has too many arguments (8/7)
13 }
14
15 // don't lint extern fns
16 extern fn extern_fn(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
17
18 pub trait Foo {
19     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
20     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());
21     //~^ ERROR: this function has too many arguments (8/7)
22
23     fn ptr(p: *const u8);
24 }
25
26 pub struct Bar;
27
28 impl Bar {
29     fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
30     fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
31     //~^ ERROR: this function has too many arguments (8/7)
32 }
33
34 // ok, we don’t want to warn implementations
35 impl Foo for Bar {
36     fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
37     fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
38
39     fn ptr(p: *const u8) {
40         println!("{}", unsafe { *p });
41         //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
42         println!("{:?}", unsafe { p.as_ref() });
43         //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
44         unsafe { std::ptr::read(p) };
45         //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
46     }
47 }
48
49 // NOT_UNSAFE_PTR_ARG_DEREF
50
51 fn private(p: *const u8) {
52     println!("{}", unsafe { *p });
53 }
54
55 pub fn public(p: *const u8) {
56     println!("{}", unsafe { *p });
57     //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
58     println!("{:?}", unsafe { p.as_ref() });
59     //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
60     unsafe { std::ptr::read(p) };
61     //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
62 }
63
64 impl Bar {
65     fn private(self, p: *const u8) {
66         println!("{}", unsafe { *p });
67     }
68
69     pub fn public(self, p: *const u8) {
70         println!("{}", unsafe { *p });
71         //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
72         println!("{:?}", unsafe { p.as_ref() });
73         //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
74         unsafe { std::ptr::read(p) };
75         //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
76     }
77
78     pub fn public_ok(self, p: *const u8) {
79         if !p.is_null() {
80             println!("{:p}", p);
81         }
82     }
83
84     pub unsafe fn public_unsafe(self, p: *const u8) {
85         println!("{}", unsafe { *p });
86         println!("{:?}", unsafe { p.as_ref() });
87     }
88 }
89
90 fn main() {}