Skip to content

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

@barafael

Description

@barafael

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

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