fn check_unsafe_derive_deserialize<'tcx>(
    cx: &LateContext<'tcx>,
    item: &Item<'_>,
    trait_ref: &TraitRef<'_>,
    ty: Ty<'tcx>,
) {
    fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> {
        let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
        cx.tcx.hir().expect_item(hir_id)
    }

    fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool {
        let mut visitor = UnsafeVisitor { cx, has_unsafe: false };
        walk_item(&mut visitor, item);
        visitor.has_unsafe
    }

    if_chain! {
        if let Some(trait_def_id) = trait_ref.trait_def_id();
        if match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE);
        if let ty::Adt(def, _) = ty.kind();
        if let Some(local_def_id) = def.did.as_local();
        let adt_hir_id = cx.tcx.hir().local_def_id_to_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))
            .any(|imp| has_unsafe(cx, imp));
        then {
            span_lint_and_help(
                cx,
                UNSAFE_DERIVE_DESERIALIZE,
                item.span,
                "you are deriving `serde::Deserialize` on a type that has methods using `unsafe`",
                None,
                "consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html"
            );
        }
    }
}
/// Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint.
Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint.
Implementation of the ` UNSAFE_DERIVE_DESERIALIZE ` lint .
fn check_unsafe_derive_deserialize<'tcx>(
    cx: &LateContext<'tcx>,
    item: &Item<'_>,
    trait_ref: &TraitRef<'_>,
    ty: Ty<'tcx>,
) {
    fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> {
        let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
        cx.tcx.hir().expect_item(hir_id)
    }
    fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool {
        let mut visitor = UnsafeVisitor { cx, has_unsafe: false };
        walk_item(&mut visitor, item);
        visitor.has_unsafe
    }
    if_chain! {
        if let Some(trait_def_id) = trait_ref.trait_def_id();
        if match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE);
        if let ty::Adt(def, _) = ty.kind();
        if let Some(local_def_id) = def.did.as_local();
        let adt_hir_id = cx.tcx.hir().local_def_id_to_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))
            .any(|imp| has_unsafe(cx, imp));
        then {
            span_lint_and_help(
                cx,
                UNSAFE_DERIVE_DESERIALIZE,
                item.span,
                "you are deriving `serde::Deserialize` on a type that has methods using `unsafe`",
                None,
                "consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html"
            );
        }
    }
}
fn check_unsafe_derive_deserialize < ' tcx > ( cx : & LateContext < ' tcx > , item : & Item < ' _ > , trait_ref : & TraitRef < ' _ > , ty : Ty < ' tcx > , ) { fn item_from_def_id < ' tcx > ( cx : & LateContext < ' tcx > , def_id : DefId ) -> & ' tcx Item < ' tcx > { let hir_id = cx . tcx . hir ( ) . local_def_id_to_hir_id ( def_id . expect_local ( ) ) ; cx . tcx . hir ( ) . expect_item ( hir_id ) } fn has_unsafe < ' tcx > ( cx : & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) -> bool { let mut visitor = UnsafeVisitor { cx , has_unsafe : false } ; walk_item ( & mut visitor , item ) ; visitor . has_unsafe } if_chain ! { if let Some ( trait_def_id ) trait_ref trait_def_id ( ) if match_def_path ( cx trait_def_id paths SERDE_DESERIALIZE ) if let ty Adt ( def ) ty kind ( ) if let Some ( local_def_id ) def did as_local ( ) let adt_hir_id cx tcx hir ( ) local_def_id_to_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 ) ) any ( imp has_unsafe ( cx imp ) ) then { span_lint_and_help ( cx UNSAFE_DERIVE_DESERIALIZE item span " " None " " ) } } }
Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint.
Implementation of the ` UNSAFE_DERIVE_DESERIALIZE ` lint .
cx
&LateContext<'tcx>
item
&Item<'_>
trait_ref
&TraitRef<'_>
ty
Ty<'tcx>
cx
&LateContext<'tcx>
item
&Item<'_>
trait_ref
&TraitRef<'_>
ty
Ty<'tcx>