]> git.lizzy.rs Git - rust.git/commitdiff
enable #[allow(clippy::unsafe_derive_deserialize)]
authorEduardo Broto <ebroto@tutanota.com>
Wed, 5 Aug 2020 22:40:11 +0000 (00:40 +0200)
committerEduardo Broto <ebroto@tutanota.com>
Wed, 5 Aug 2020 22:45:30 +0000 (00:45 +0200)
clippy_lints/src/derive.rs
tests/ui/unsafe_derive_deserialize.rs

index 08d8100a88545bc7ee8ada5d6ec8bc6f92e992dc..80a0675898240633e73830d6dc6a649df326c7ef 100644 (file)
@@ -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 has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool {
     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))
index 7bee9c499e1f32373090b85cdbd4dcf5755f832d..690d705573d3f73ae3bba84c7dfb4a97d35e87fb 100644 (file)
@@ -57,4 +57,14 @@ unsafe fn inner() {}
 #[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() {}