Skip to content

use_self with different lifetimes #13277

@EdJoPaTo

Description

@EdJoPaTo

Summary

use_self seems to trigger even when the lifetimes are different here. Using --fix doesn't work as the resulting code doesn't compile. (Which is good that --fix doesn't try to fix anything then)

Noticed here: https://github.com/bevyengine/bevy/blob/423285cf1cbd86d85db066dbfe26de4fd68333d9/crates/bevy_ecs/src/system/system_param.rs#L537

Lint Name

use_self

Reproducer

#![warn(clippy::use_self)]
trait Foo {
    type Item<'foo>;
}
struct Bar<'b> {
    content: &'b str,
}
impl<'b> Foo for Option<Bar<'b>> {
    type Item<'foo> = Option<Bar<'foo>>;
}

I saw this happen:

warning: unnecessary structure name repetition
  --> src/main.rs:16:23
   |
16 |     type Item<'foo> = Option<Bar<'foo>>;
   |                       ^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

I expected to see this happen: The lint should not trigger here. These are different lifetimes.

Version

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7

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