]> git.lizzy.rs Git - rust.git/blob - tests/ui/unsafe_derive_deserialize.rs
[`excessive_bools`] lint trait functions even without bodies
[rust.git] / tests / ui / unsafe_derive_deserialize.rs
1 #![warn(clippy::unsafe_derive_deserialize)]
2 #![allow(unused, clippy::missing_safety_doc)]
3
4 extern crate serde;
5
6 use serde::Deserialize;
7
8 #[derive(Deserialize)]
9 pub struct A;
10 impl A {
11     pub unsafe fn new(_a: i32, _b: i32) -> Self {
12         Self {}
13     }
14 }
15
16 #[derive(Deserialize)]
17 pub struct B;
18 impl B {
19     pub unsafe fn unsafe_method(&self) {}
20 }
21
22 #[derive(Deserialize)]
23 pub struct C;
24 impl C {
25     pub fn unsafe_block(&self) {
26         unsafe {}
27     }
28 }
29
30 #[derive(Deserialize)]
31 pub struct D;
32 impl D {
33     pub fn inner_unsafe_fn(&self) {
34         unsafe fn inner() {}
35     }
36 }
37
38 // Does not derive `Deserialize`, should be ignored
39 pub struct E;
40 impl E {
41     pub unsafe fn new(_a: i32, _b: i32) -> Self {
42         Self {}
43     }
44
45     pub unsafe fn unsafe_method(&self) {}
46
47     pub fn unsafe_block(&self) {
48         unsafe {}
49     }
50
51     pub fn inner_unsafe_fn(&self) {
52         unsafe fn inner() {}
53     }
54 }
55
56 // Does not have methods using `unsafe`, should be ignored
57 #[derive(Deserialize)]
58 pub struct F;
59
60 // Check that we honor the `allow` attribute on the ADT
61 #[allow(clippy::unsafe_derive_deserialize)]
62 #[derive(Deserialize)]
63 pub struct G;
64 impl G {
65     pub fn unsafe_block(&self) {
66         unsafe {}
67     }
68 }
69
70 fn main() {}