]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-unsafe-code.rs
Merge commit 'ff0993c5e9162ddaea78e83d0f0161e68bd4ea73' into clippy
[rust.git] / src / test / ui / lint / lint-unsafe-code.rs
1 #![allow(unused_unsafe)]
2 #![allow(dead_code)]
3 #![deny(unsafe_code)]
4
5 struct Bar;
6 struct Bar2;
7 struct Bar3;
8
9 #[allow(unsafe_code)]
10 mod allowed_unsafe {
11     fn allowed() { unsafe {} }
12     unsafe fn also_allowed() {}
13     unsafe trait AllowedUnsafe { }
14     unsafe impl AllowedUnsafe for super::Bar {}
15 }
16
17 macro_rules! unsafe_in_macro {
18     () => {
19         unsafe {} //~ ERROR: usage of an `unsafe` block
20     }
21 }
22
23 unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function
24 unsafe trait Foo {} //~ ERROR: declaration of an `unsafe` trait
25 unsafe impl Foo for Bar {} //~ ERROR: implementation of an `unsafe` trait
26
27 trait Baz {
28     unsafe fn baz(&self); //~ ERROR: declaration of an `unsafe` method
29     unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method
30     unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method
31 }
32
33 impl Baz for Bar {
34     unsafe fn baz(&self) {} //~ ERROR: implementation of an `unsafe` method
35     unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method
36 }
37
38
39 #[allow(unsafe_code)]
40 trait A {
41     unsafe fn allowed_unsafe(&self);
42     unsafe fn allowed_unsafe_provided(&self) {}
43 }
44
45 #[allow(unsafe_code)]
46 impl Baz for Bar2 {
47     unsafe fn baz(&self) {}
48     unsafe fn provided_override(&self) {}
49 }
50
51 impl Baz for Bar3 {
52     #[allow(unsafe_code)]
53     unsafe fn baz(&self) {}
54     unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method
55 }
56
57 #[allow(unsafe_code)]
58 unsafe trait B {
59     fn dummy(&self) {}
60 }
61
62 trait C {
63     #[allow(unsafe_code)]
64     unsafe fn baz(&self);
65     unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method
66 }
67
68 impl C for Bar {
69     #[allow(unsafe_code)]
70     unsafe fn baz(&self) {}
71     unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method
72 }
73
74 impl C for Bar2 {
75     unsafe fn baz(&self) {} //~ ERROR: implementation of an `unsafe` method
76 }
77
78 trait D {
79     #[allow(unsafe_code)]
80     unsafe fn unsafe_provided(&self) {}
81 }
82
83 impl D for Bar {}
84
85 fn main() {
86     unsafe {} //~ ERROR: usage of an `unsafe` block
87
88     unsafe_in_macro!()
89 }