]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
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)] | |
781aab86 | 9 | //~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe |
04454e1e | 10 | pub struct A; |
f20569fa XL |
11 | impl A { |
12 | pub unsafe fn new(_a: i32, _b: i32) -> Self { | |
13 | Self {} | |
14 | } | |
15 | } | |
16 | ||
17 | #[derive(Deserialize)] | |
781aab86 | 18 | //~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe |
04454e1e | 19 | pub struct B; |
f20569fa XL |
20 | impl B { |
21 | pub unsafe fn unsafe_method(&self) {} | |
22 | } | |
23 | ||
24 | #[derive(Deserialize)] | |
781aab86 | 25 | //~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe |
04454e1e | 26 | pub struct C; |
f20569fa XL |
27 | impl C { |
28 | pub fn unsafe_block(&self) { | |
29 | unsafe {} | |
30 | } | |
31 | } | |
32 | ||
33 | #[derive(Deserialize)] | |
781aab86 | 34 | //~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe |
04454e1e | 35 | pub struct D; |
f20569fa XL |
36 | impl D { |
37 | pub fn inner_unsafe_fn(&self) { | |
38 | unsafe fn inner() {} | |
39 | } | |
40 | } | |
41 | ||
42 | // Does not derive `Deserialize`, should be ignored | |
04454e1e | 43 | pub struct E; |
f20569fa XL |
44 | impl E { |
45 | pub unsafe fn new(_a: i32, _b: i32) -> Self { | |
46 | Self {} | |
47 | } | |
48 | ||
49 | pub unsafe fn unsafe_method(&self) {} | |
50 | ||
51 | pub fn unsafe_block(&self) { | |
52 | unsafe {} | |
53 | } | |
54 | ||
55 | pub fn inner_unsafe_fn(&self) { | |
56 | unsafe fn inner() {} | |
57 | } | |
58 | } | |
59 | ||
60 | // Does not have methods using `unsafe`, should be ignored | |
61 | #[derive(Deserialize)] | |
04454e1e | 62 | pub struct F; |
f20569fa XL |
63 | |
64 | // Check that we honor the `allow` attribute on the ADT | |
65 | #[allow(clippy::unsafe_derive_deserialize)] | |
66 | #[derive(Deserialize)] | |
04454e1e | 67 | pub struct G; |
f20569fa XL |
68 | impl G { |
69 | pub fn unsafe_block(&self) { | |
70 | unsafe {} | |
71 | } | |
72 | } | |
73 | ||
74 | fn main() {} |