Skip to content

linkme v0.3.25 and up fire clippy::ref-option-ref when constructing a slice of Option<&'static Foo> #103

@smalis-msft

Description

@smalis-msft

This does not occur on v0.3.24. Encountered this when trying to update OpenVMM to v0.3.30.

Code example:

    // Use Option<&X> in case the linker inserts some stray nulls, as we think
    // it might on Windows.
    //
    // See <https://devblogs.microsoft.com/oldnewthing/20181108-00/?p=100165>.
    #[linkme::distributed_slice]
    pub static WORKERS: [Option<&'static RegisteredWorker>] = [..];

    // Always have at least one entry to work around linker bugs.
    //
    // See <https://github.com/llvm/llvm-project/issues/65855>.
    #[linkme::distributed_slice(WORKERS)]
    static WORKAROUND: Option<&'static RegisteredWorker> = None;

Output:

warning: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>`
   --> support/mesh/mesh_worker/src/worker.rs:624:5
    |
624 |     #[linkme::distributed_slice(WORKERS)]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
    = note: requested on the command line with `-W clippy::ref-option-ref`
    = note: this warning originates in the attribute macro `linkme::distributed_slice` (in Nightly builds, run with -Z macro-backtrace for more info)

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