Skip to content

Extend use_self to structs #15555

@nickdrozd

Description

@nickdrozd

Summary

Existing lint use_self check impl blocks for places where Self could be used instead of explicit repetition of type.

The same can be done with recursive structs. For example:

struct X {
    x: Option<Box<X>>,  // <-- repetition
}
struct X {
    x: Option<Box<Self>>,  // <-- no repetition
}

Self is very nice to have if the struct is modified to be generic.

struct X<'q, T: From<usize>> {
    t: &'q T,
    x: Option<Box<X<'q, T>>>,  // <-- yuck
}

Opened as false negative, but might also be a "feature-request in a trench coat" 😆

Lint Name

use_self

Reproducer

Should raise use_self:

struct X {
    x: Option<Box<X>>,  // <-- Self
}
struct X<'q, T: From<usize>> {
    t: &'q T,
    x: Option<Box<X<'q, T>>>,  // <-- Self
}

Version

rustc 1.91.0-nightly (6ba0ce409 2025-08-21)
binary: rustc
commit-hash: 6ba0ce40941eee1ca02e9ba49c791ada5158747a
commit-date: 2025-08-21
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions