]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/unsafe_derive_deserialize.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / unsafe_derive_deserialize.rs
CommitLineData
f20569fa
XL
1#![warn(clippy::unsafe_derive_deserialize)]
2#![allow(unused, clippy::missing_safety_doc)]
3
4extern crate serde;
5
6use serde::Deserialize;
7
8#[derive(Deserialize)]
781aab86 9//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe
04454e1e 10pub struct A;
f20569fa
XL
11impl 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 19pub struct B;
f20569fa
XL
20impl 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 26pub struct C;
f20569fa
XL
27impl 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 35pub struct D;
f20569fa
XL
36impl D {
37 pub fn inner_unsafe_fn(&self) {
38 unsafe fn inner() {}
39 }
40}
41
42// Does not derive `Deserialize`, should be ignored
04454e1e 43pub struct E;
f20569fa
XL
44impl 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 62pub 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 67pub struct G;
f20569fa
XL
68impl G {
69 pub fn unsafe_block(&self) {
70 unsafe {}
71 }
72}
73
74fn main() {}