Code Monkey home page Code Monkey logo

Comments (7)

llogiq avatar llogiq commented on August 23, 2024

I think that one should be simple enough to detect, and it's also easy to create a good warning. I'd catch all instances of if { Lit:bool } else { Lit:bool } and suggest a suitable replacement based on the literals.

I'll take a stab at it when I find some free time.

from rust-clippy.

Manishearth avatar Manishearth commented on August 23, 2024

Yep, it's pretty simple. Go ahead! :)

from rust-clippy.

kmcallister avatar kmcallister commented on August 23, 2024

I'd catch all instances of if { Lit:bool } else { Lit:bool } and suggest a suitable replacement based on the literals.

It'd be great to have a general, declarative way to express rules like that. Maybe something similar to Coccinelle.

from rust-clippy.

Manishearth avatar Manishearth commented on August 23, 2024

Technically it's just a single huge match statement (assuming syntax::ptr::P doesn't get in the way) ;)

from rust-clippy.

kmcallister avatar kmcallister commented on August 23, 2024

It would be cool to do this with quotation:

fn check_expr(&mut self, cx: &Context, expr: &Expr) {
    match *expr {
        q!(if $e:expr { $a:lit } else { $b:lit }) => ...

I think this is actually achievable now, if you replace the whole match by an invocation of a procedural macro, similar to html5ever's match_token!.

from rust-clippy.

llogiq avatar llogiq commented on August 23, 2024

A macro should be able to generate code to deal with ptr::P, as irritating as it sometimes is. But until we have this macro, I'm going to write the lint the traditional way.

from rust-clippy.

llogiq avatar llogiq commented on August 23, 2024

Done. The warnings could give more specific directions (they are a bit abstract for a newbie), but it works, and it's late now; I guess, I'll revisit them later.

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.