Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
Tracked by #288
smalis-msft opened this issue Nov 12, 2024 · 0 comments · Fixed by #104

Comments

@smalis-msft
Copy link

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)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant