Skip to content

needless_borrow should trigger when taking a reference to Option<&_> #11326

Closed as not planned
@jplatte

Description

@jplatte

Lint Name

needless_borrow

Reproducer

I tried this code:

struct Object;

impl Object {
    fn str_getter(&self) -> Option<&str> {
        None
    }
}

fn main() {
    let o = Object;
    if let Some(s) = &o.str_getter() {
        println!("{s}");
    }
}

I expected to see this happen: needless_borrow triggering for &o.str_getter()

Instead, this happened: nothing

Version

Tested on Rust playground, hence less info. Let me know if you need me to reproduce locally.

Nightly version: 1.73.0-nightly
(2023-08-10 439d066bcf9496b1b8c8)

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