Skip to content

str_to_string does not trigger inside a map function #16511

@xtqqczze

Description

@xtqqczze

Summary

If you try to use ToString::to_string in a map function on an option, the lint does not trigger.

Lint Name

str_to_string

Reproducer

I tried this code:

pub fn m1(x: Option<&str>) -> Option<String> {
    x.map(ToString::to_string)
}

https://godbolt.org/z/6f8zz67ac

I expected to see this happen:

warning: `to_string()` called on a `&str`

Instead, this happened:

Lint did not trigger

Version


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