Skip to content

Private constructor is flagged by manual_non_exhaustive #12106

Closed
@SUPERCILEX

Description

@SUPERCILEX

Summary

If I want a private constructor in a private module, the way to do so AFAIK is to create a private unused field. Non-exhaustiveness still lets you create the struct from within your own crate (which is not what I want), so the lint shouldn't apply.

Lint Name

manual_non_exhaustive

Reproducer

Repro: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=25882b81cd17475473930b2e275252c1
Try switching to non_exhaustive and you'll see that the doesnt_compile line will actually work if you comment it out (that's bad).

Real code:

    pub struct BoxedEntry {
        pub ptr: ExtPtr,
        pub op_fn: unsafe fn(ExtPtr, BoxedEntryOp),
        _private: (),
    }

    impl BoxedEntry {
        pub fn new<T: Send + Sync + 'static>(val: T) -> Self {
            Self {
                ptr: ExtPtr::new(val),
                op_fn: run_boxed_entry_op::<T>,
                _private: (),
            }
        }
    }

Version

No response

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions