Skip to content

Commit

Permalink
Rollup merge of #5870 - ebroto:5789_allow_unsafe_derive_deserialize, …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
flip1995 authored Aug 10, 2020
2 parents 8ee57ee + 50a86d4 commit 08ab29b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/unsafe_derive_deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

0 comments on commit 08ab29b

Please sign in to comment.