Skip to content

declare_interior_mutable_const for Option #5050

Closed
@Byter09

Description

@Byter09

Hello!

This trait

pub trait SomeTrait {
    const VAL: Option<Self>;
}

triggers

error: a const item should never be interior mutable
  |
6 |     const VAL: Option<Self>;
  |     ^^^^^^^^^^^------------^
  |                |
  |                consider requiring `std::option::Option<Self>` to be `Copy`
  |

which is this lint: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const

Apparently the corresponding test is this? https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/non_copy_const.rs (not sure!)

Thing is, it doesnt test Option<T> and additionally: is interior mutability for const Options even such a big deal?

I'm simply trying to figure out if I'm implementing a foot-gun right now if I allow this. I don't intent to ever manipulate this const and will only use it for PartialEq and Eq purposes.

EDIT: @frozolotl on Discord suggested removing Option from the trait and it should indeed still trigger. And it does. Note: The suggestion to require Copy is not possible in my case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-needs-discussionStatus: Needs further discussion before merging or work can be started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions