Skip to content

declare_interior_mutable_const and borrow_interior_mutable_const need to respect enum variants #3962

Closed
@devsnek

Description

@devsnek
#[derive(Debug)]
enum Thing {
	// variant A has interior mutability
    A(std::cell::Cell<bool>),
	// variant B clearly does not
    B,
}

impl Thing {
    // declare_interior_mutable_const triggers here
    pub const BB: Thing = Thing::B;
}

fn main() {
    // borrow_interior_mutable_const triggers here
    println!("Thing::BB = {:?}", Thing::BB);
}

I realize that it isn't possible to know if the thing on the rhs of a const declaration is interior mutable or not without full const evaluation, but trivial cases such as the example shouldn't be too difficult.

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