Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

incompatible_msrv false positive: Trait methods of the same name #12280

Open
joshlf opened this issue Feb 12, 2024 · 1 comment
Open

incompatible_msrv false positive: Trait methods of the same name #12280

joshlf opened this issue Feb 12, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@joshlf
Copy link

joshlf commented Feb 12, 2024

Summary

The incompatible_msrv lint fires when a method was stabilized more recently than the MSRV, but there is also a trait in scope with a method of the same name. In this case, on toolchains prior to stabilization, the trait's method will be chosen instead, and so compilation will still succeed. This technique is sometimes used to implement polyfills.

To repro, run cargo +nightly-2024-02-12 clippy -p zerocopy-derive at this commit:

$ cargo +nightly-2024-02-12 clippy -p zerocopy-derive
   Compiling proc-macro2 v1.0.76
    Checking unicode-ident v1.0.12
    Checking quote v1.0.35
    Checking syn v2.0.48
    Checking zerocopy-derive v0.8.0-alpha.4 (/Users/josh/workspace/zerocopy/zerocopy-derive)
error: current MSRV (Minimum Supported Rust Version) is `1.56.0` but this item is stable since `1.62.0`
   --> zerocopy-derive/src/lib.rs:943:83
    |
943 |     let padding_check_bound = padding_check.and_then(|check| (!fields.is_empty()).then_some(check)).map(|check| {
    |                                                                                   ^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
note: the lint level is defined here
   --> zerocopy-derive/src/lib.rs:19:9
    |
19  | #![deny(clippy::all, clippy::missing_safety_doc, clippy::undocumented_unsafe_blocks)]
    |         ^^^^^^^^^^^
    = note: `#[deny(clippy::incompatible_msrv)]` implied by `#[deny(clippy::all)]`

error: could not compile `zerocopy-derive` (lib) due to 1 previous error

The following code also exists in the same module:

// A polyfill for `Option::then_some`, which was added after our MSRV.
//
// The `#[allow(unused)]` is necessary because, on sufficiently recent toolchain
// versions, `b.then_some(...)` resolves to the inherent method rather than to
// this trait, and so this trait is considered unused.
//
// TODO(#67): Remove this once our MSRV is >= 1.62.
#[allow(unused)]
trait BoolExt {
    fn then_some<T>(self, t: T) -> Option<T>;
}

impl BoolExt for bool {
    fn then_some<T>(self, t: T) -> Option<T> {
        if self {
            Some(t)
        } else {
            None
        }
    }
}

Lint Name

incompatible_msrv

Version

nightly-2024-02-12

@joshlf joshlf added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 12, 2024
taiki-e added a commit to smol-rs/piper that referenced this issue May 13, 2024
rust-lang/rust-clippy#12280

```
error: current MSRV (Minimum Supported Rust Version) is `1.36.0` but this item is stable since `1.37.0`
   --> src/lib.rs:224:20
    |
224 |     let buffer = v.as_mut_ptr();
    |                    ^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
    = note: `-D clippy::incompatible-msrv` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
```
notgull pushed a commit to smol-rs/piper that referenced this issue May 14, 2024
rust-lang/rust-clippy#12280

```
error: current MSRV (Minimum Supported Rust Version) is `1.36.0` but this item is stable since `1.37.0`
   --> src/lib.rs:224:20
    |
224 |     let buffer = v.as_mut_ptr();
    |                    ^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
    = note: `-D clippy::incompatible-msrv` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
```
@bluss
Copy link
Member

bluss commented Jul 26, 2024

This also happens for the new NonNull methods vs the PointerExt methods of the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants