Giter Site home page Giter Site logo

Comments (7)

m-rph avatar m-rph commented on June 12, 2024 1

Right the suggestion will introduce more errors. Could we limit it to just a warning and suspicious?

from rust-clippy.

m-rph avatar m-rph commented on June 12, 2024

I accidentally created such a bug and the only reason I caught it was because my condition was _ => if ... and not (_, 1) => if ..., and thus rustc complained about the final wildcard being unreachable.

from rust-clippy.

Alexendoo avatar Alexendoo commented on June 12, 2024

This may catch bugs, but it would have far too many false positives. For correct code the suggestion conflicts with match_same_arms/wildcard_in_or_patterns also

Notably rustfmt does not allow you to have PAT => if ..., it will always wrap it in a block to reduce the confusion here

from rust-clippy.

Alexendoo avatar Alexendoo commented on June 12, 2024

IMO the number of false positives would make it unable to be above restriction

A perhaps equivalent restriction lint would be to lint on all uses of guards in match arms

from rust-clippy.

m-rph avatar m-rph commented on June 12, 2024

But that's not the same, is it? the intention is basically to disallow pat => if and pat => { if ... {rest} } and instead recommend pat if ... => {rest}

from rust-clippy.

Alexendoo avatar Alexendoo commented on June 12, 2024

The other way, requiring every guard (pat if ... =>) to become pat if ... => { ... }; pat => { ... } seems equivalent but less direct than forbidding guards, so instead pat => { if ... { ... } else { ... } }

from rust-clippy.

m-rph avatar m-rph commented on June 12, 2024

That makes sense. It feels too restrictive though, doesn't it? It increases nesting by an additional level.

I think we can close this as not to be implemented, but I'd love a way to ensure this accident doesn't happen.

from rust-clippy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.