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

multiple-bound-locations reports on ?Sized which cannot be in the where clause #12640

Closed
barafael opened this issue Apr 6, 2024 · 3 comments
Closed
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

@barafael
Copy link

barafael commented Apr 6, 2024

Summary

The new-ish multiple-bound-locations lint fires on unfixable code.

Lint Name

multiple-bound-locations

Reproducer

I tried this code:

    pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
    where
        K: Borrow<Q>,
        Q: Hash + Eq,
    {
        for i in 0..self.entries.len() {
            if self.entries[i].0.borrow() == k {
                return Some(self.entries.swap_remove(i).1);
            }
        }

        None
    }

taken from: https://github.com/tokio-rs/tokio/blob/035a968bddcadcbfeff02efa7ccf1f5d9b69f149/tokio-stream/src/stream_map.rs#L470-L482

I saw this happen:

warning: bound is defined in more than one place
   --> tokio-stream/src/stream_map.rs:470:19
    |
470 |     pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
    |                   ^
...
473 |         Q: Hash + Eq,
    |         ^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
    = note: `#[warn(clippy::multiple_bound_locations)]` on by default

I expected to see this happen: No lint fired here, as long as ?Sized cannot live in a where-clause.

Version

rustc 1.79.0-nightly (4fd4797c2 2024-04-03)
binary: rustc
commit-hash: 4fd4797c2654977f545c9a91e2aa4e6cdbb38919
commit-date: 2024-04-03
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

@barafael barafael 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 Apr 6, 2024
@barafael
Copy link
Author

barafael commented Apr 6, 2024

related: rust-lang/rust#20503

@barafael
Copy link
Author

barafael commented Apr 6, 2024

i was wrong, pls ignore

@barafael barafael closed this as completed Apr 6, 2024
@y21
Copy link
Member

y21 commented Apr 6, 2024

This is true for old versions of Rust (pre 1.15), and clippy currently doesn't respect the msrv configuration for this lint, so there's indeed a bug here when the MSRV is set to lower than that.

However, this has already been reported in #12370, and will be fixed by #12388, so more of a duplicate in that regard :)

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