Skip to content

Suppress clippy lint for atomics #11

Description

@rust1248

When I try to use this crate on a struct with atomics, clippy complains about the following:

warning: a `const` item should never be interior mutable
  --> src/main.rs:14:5
   |
14 | /     const DEFAULT: Self = Self {
15 | |         atomic: <AtomicUsize as ::const_default::ConstDefault>::DEFAULT,
16 | |     };
   | |______^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
   = note: `#[warn(clippy::declare_interior_mutable_const)]` on by default

This is the code I used:

use std::sync::atomic::AtomicUsize;

static T: Test = <Test as const_default::ConstDefault>::DEFAULT;

#[derive(Debug)]
struct Test {
    atomic: AtomicUsize,
}

impl ::const_default::ConstDefault for Test
where
    AtomicUsize: ::const_default::ConstDefault,
{
    const DEFAULT: Self = Self {
        atomic: <AtomicUsize as ::const_default::ConstDefault>::DEFAULT,
    };
}

fn main() {
    dbg!(&T);
}

I think the crate should add a #[allow(clippy::declare_interior_mutable_const)] above const DEFAULT: Self = Self {, so that it stops complaining

I can open a PR if you are interested

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions