Skip to content

unsafe_derive_deserialize can't be enabled/disabled per struct #5789

Closed
@alecmocatta

Description

@alecmocatta

clippy::unsafe_derive_deserialize can't be allowed/warned/denied by outer attributes on the struct or its impls. Minor inconvenience but might be worth making one of these allows functional?

#![allow(dead_code, unused_unsafe)]
#![warn(clippy::unsafe_derive_deserialize)]

use serde::Deserialize;

#[allow(clippy::unsafe_derive_deserialize)]
#[derive(Deserialize)]
struct Foo;

#[allow(clippy::unsafe_derive_deserialize)]
impl Foo {
    fn bar(&mut self) {
        let _ = self;
        unsafe {}
    }
}

(Playground)

Clippy:

    Checking playground v0.0.1 (/playground)
warning: you are deriving `serde::Deserialize` on a type that has methods using `unsafe`
 --> src/lib.rs:7:10
  |
7 | #[derive(Deserialize)]
  |          ^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/lib.rs:2:9
  |
2 | #![warn(clippy::unsafe_derive_deserialize)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_derive_deserialize
  = note: this warning originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions