Skip to content

needless_borrow suggests bad code when reference-to-reference is required #2610

Closed
@scurest

Description

@scurest
struct S<'a>(&'a str);

impl<'a> std::fmt::Debug for S<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match *self {

            // This suggests changing `ref s` to `s`, which won't compile
            // (`field` takes a `&Debug`).
            S(ref s) => f.debug_tuple("S").field(s).finish()

            // I'm aware you can do this.
            //S(s) => f.debug_tuple("S").field(&s).finish()
        }

    }
}

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=21db39fed7d5b0778b382e206fa45f1b

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions