Skip to content

Commit 50a86d4

Browse files
committed
enable #[allow(clippy::unsafe_derive_deserialize)]
1 parent 2d4c337 commit 50a86d4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

clippy_lints/src/derive.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::paths;
22
use crate::utils::{
3-
get_trait_def_id, is_automatically_derived, is_copy, match_path, span_lint_and_help, span_lint_and_note,
4-
span_lint_and_then,
3+
get_trait_def_id, is_allowed, is_automatically_derived, is_copy, match_path, span_lint_and_help,
4+
span_lint_and_note, span_lint_and_then,
55
};
66
use if_chain::if_chain;
77
use rustc_hir::def_id::DefId;
@@ -354,7 +354,9 @@ fn check_unsafe_derive_deserialize<'tcx>(
354354
if_chain! {
355355
if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE);
356356
if let ty::Adt(def, _) = ty.kind;
357-
if def.did.is_local();
357+
if let Some(local_def_id) = def.did.as_local();
358+
let adt_hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
359+
if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
358360
if cx.tcx.inherent_impls(def.did)
359361
.iter()
360362
.map(|imp_did| item_from_def_id(cx, *imp_did))

tests/ui/unsafe_derive_deserialize.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@ impl E {
5757
#[derive(Deserialize)]
5858
pub struct F {}
5959

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+
6070
fn main() {}

0 commit comments

Comments
 (0)