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

match_ref_pats should lint against if let (ref x) = *x #5038

Open
Luro02 opened this issue Jan 10, 2020 · 2 comments
Open

match_ref_pats should lint against if let (ref x) = *x #5038

Luro02 opened this issue Jan 10, 2020 · 2 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-style Lint: Belongs in the style lint group

Comments

@Luro02
Copy link

Luro02 commented Jan 10, 2020

This is pointless and has no benefit:

if let ErrorKind::Multiple(ref items) = *self

This is how it should be written

if let ErrorKind::Multiple(items) = &self
@JohnTitor JohnTitor added L-style Lint: Belongs in the style lint group C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Jan 11, 2020
@matthiaskrgr
Copy link
Member

Similar case:

enum Wrapper {
    A(String),
    B(String),
    C(String),
}

impl Wrapper {
    fn inner(&self) -> &String {
        match self {
            &Wrapper::A(ref inner) => inner,
            &Wrapper::B(ref inner) => inner,
            &Wrapper::C(ref inner) => inner,
        }
    }
}

Clippy suggests

match *self  {
   Wrapper::A(ref inner) => inner,
   ...

But it it would be better to suggest

   fn inner(&self) -> &String {
        match self {
            Wrapper::A(inner) => inner,
            Wrapper::B(inner) => inner,
            Wrapper::C(inner) => inner,
        }
    }

@Tanja-4732
Copy link

Has the suggestion from @matthiaskrgr been implemented yet? What's the status on it?

Clippy still suggests the asterisk both in stable and nightly:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e5449fb7e2e56fecb09556aba25c7cc6
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e5449fb7e2e56fecb09556aba25c7cc6

Steps to reproduce:

  1. Open (either or both) link(s) from above
  2. Click "Tools" on the top-right corner of the screen
  3. Click on "Clippy" (an wait)

Some questions

  • Will this be fixed?
  • If so, when?
  • Should a new issue be opened?

PS: also referencing #4961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-style Lint: Belongs in the style lint group
Projects
None yet
Development

No branches or pull requests

4 participants