Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scurest opened this issue Apr 1, 2018 · 4 comments · Fixed by #7105
Closed

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

scurest opened this issue Apr 1, 2018 · 4 comments · Fixed by #7105
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@scurest
Copy link
Contributor

scurest commented Apr 1, 2018

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

@Manishearth
Copy link
Member

I think the idiomatic way of doing that is field(&s), but this is still a bug

@oli-obk oli-obk added the C-bug Category: Clippy is not doing the correct thing label Apr 1, 2018
@phansch

This comment has been minimized.

@phansch phansch closed this as completed Dec 18, 2020
@taiki-e

This comment has been minimized.

@phansch

This comment has been minimized.

@phansch phansch reopened this Dec 20, 2020
@phansch phansch added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 21, 2020
@bors bors closed this as completed in 029c326 May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants