Skip to content

False positive for use_self with trait bounds #7139

@lukas-code

Description

@lukas-code

Lint name: use_self

I tried this code:

#![deny(clippy::use_self)]

trait Trait {}

impl<I> Trait for I
where
    I: Iterator,
    I::Item: Trait,
{}

I expected to see this happen: no clippy output

Instead, this happened:

    Checking playground v0.0.1 (/playground)
error: unnecessary structure name repetition
 --> src/lib.rs:9:5
  |
9 |     I::Item: Trait,
  |     ^ help: use the applicable keyword: `Self`
  |
note: the lint level is defined here
 --> src/lib.rs:2:9
  |
2 | #![deny(clippy::use_self)]
  |         ^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

The following works as expected, but is a lot less readable:

#![deny(clippy::use_self)]

trait Trait {}

impl<I> Trait for I
where
    I: Iterator,
    <Self as Iterator>::Item: Trait,
{}

Leaving out as Iterator will fail to compile.

Meta

  • cargo clippy -V: clippy 0.1.53 (6df26f8 2021-04-20)
  • rustc -Vv:
rustc 1.53.0-nightly (6df26f897 2021-04-20)
binary: rustc
commit-hash: 6df26f897cffb2d86880544bb451c6b5f8509b2d
commit-date: 2021-04-20
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.I-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