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 { new(_a: i32, _b: i32) -> Self11 pub unsafe fn new(_a: i32, _b: i32) -> Self { 12 Self {} 13 } 14 } 15 16 #[derive(Deserialize)] 17 pub struct B {} 18 impl B { unsafe_method(&self)19 pub unsafe fn unsafe_method(&self) {} 20 } 21 22 #[derive(Deserialize)] 23 pub struct C {} 24 impl C { unsafe_block(&self)25 pub fn unsafe_block(&self) { 26 unsafe {} 27 } 28 } 29 30 #[derive(Deserialize)] 31 pub struct D {} 32 impl D { inner_unsafe_fn(&self)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 { new(_a: i32, _b: i32) -> Self41 pub unsafe fn new(_a: i32, _b: i32) -> Self { 42 Self {} 43 } 44 unsafe_method(&self)45 pub unsafe fn unsafe_method(&self) {} 46 unsafe_block(&self)47 pub fn unsafe_block(&self) { 48 unsafe {} 49 } 50 inner_unsafe_fn(&self)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 { unsafe_block(&self)65 pub fn unsafe_block(&self) { 66 unsafe {} 67 } 68 } 69 main()70fn main() {} 71