about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2020-08-10 14:56:27 +0200
committerGitHub <noreply@github.com>2020-08-10 14:56:27 +0200
commit08ab29bed13c2728b8f9d306af23ad5f10517843 (patch)
tree3de75007fa5053e58dab711fd090ce0e703e9b89
parent8ee57eed79ed4f7c9ce21b4a6dae6daad62193c1 (diff)
parent50a86d492718f2ad5e653575d19324205fa007f1 (diff)
downloadrust-08ab29bed13c2728b8f9d306af23ad5f10517843.tar.gz
rust-08ab29bed13c2728b8f9d306af23ad5f10517843.zip
Rollup merge of #5870 - ebroto:5789_allow_unsafe_derive_deserialize, r=flip1995
enable #[allow(clippy::unsafe_derive_deserialize)]

Before this change this lint could not be allowed as the code we are checking is automatically generated.

changelog: Enable using the `allow` attribute on top of an ADT linted by [`unsafe_derive_deserialize`].

Fixes: #5789
-rw-r--r--clippy_lints/src/derive.rs8
-rw-r--r--tests/ui/unsafe_derive_deserialize.rs10
2 files changed, 15 insertions, 3 deletions
diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs
index 08d8100a885..80a06758982 100644
--- a/clippy_lints/src/derive.rs
+++ b/clippy_lints/src/derive.rs
@@ -1,7 +1,7 @@
 use crate::utils::paths;
 use crate::utils::{
-    get_trait_def_id, is_automatically_derived, is_copy, match_path, span_lint_and_help, span_lint_and_note,
-    span_lint_and_then,
+    get_trait_def_id, is_allowed, is_automatically_derived, is_copy, match_path, span_lint_and_help,
+    span_lint_and_note, span_lint_and_then,
 };
 use if_chain::if_chain;
 use rustc_hir::def_id::DefId;
@@ -354,7 +354,9 @@ fn check_unsafe_derive_deserialize<'tcx>(
     if_chain! {
         if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE);
         if let ty::Adt(def, _) = ty.kind;
-        if def.did.is_local();
+        if let Some(local_def_id) = def.did.as_local();
+        let adt_hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
+        if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
         if cx.tcx.inherent_impls(def.did)
             .iter()
             .map(|imp_did| item_from_def_id(cx, *imp_did))
diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs
index 7bee9c499e1..690d705573d 100644
--- a/tests/ui/unsafe_derive_deserialize.rs
+++ b/tests/ui/unsafe_derive_deserialize.rs
@@ -57,4 +57,14 @@ impl E {
 #[derive(Deserialize)]
 pub struct F {}
 
+// Check that we honor the `allow` attribute on the ADT
+#[allow(clippy::unsafe_derive_deserialize)]
+#[derive(Deserialize)]
+pub struct G {}
+impl G {
+    pub fn unsafe_block(&self) {
+        unsafe {}
+    }
+}
+
 fn main() {}