Giter Site home page Giter Site logo

Name Shadowing about rust-clippy HOT 8 CLOSED

rust-lang avatar rust-lang commented on May 20, 2024 3
Name Shadowing

from rust-clippy.

Comments (8)

Manishearth avatar Manishearth commented on May 20, 2024

I think shadowing is quite liberally used in Rust, so we should tread lightly here.

I think your proposed scheme should work well.

I think especially in nested libsyntax code it's quite common to shadow and re-shadow stuff like ty and expr because they end up being used a lot. But those users can just disable the lint.

from rust-clippy.

llogiq avatar llogiq commented on May 20, 2024

I know that many don't see shadowing as a problem. But I maintain that it does make code harder to visually parse than strictly necessary (where does that foo come from again?). And often, reusing a binding stems from lazyness to think up a more specific name.

Btw. scopes are a good antidote to shadowing – if a binding is out of scope, it cannot shadow anything. Thus, reducing scopes also reduces shadowing.

I'd really like to see how many warnings libsyntax would generate with shadow_foreign turned on. 😄

from rust-clippy.

Manishearth avatar Manishearth commented on May 20, 2024

Sounds good to me.

from rust-clippy.

llogiq avatar llogiq commented on May 20, 2024

I see you added [T-middle]. Is there something that would ease building this?

I figure it would be possible to implement this by walking the AST of any fn and keeping a chain of sets of local bindings (one for each scope), but perhaps there is an easier solution?

from rust-clippy.

Manishearth avatar Manishearth commented on May 20, 2024

I guess an AST walk would work. I was thinking along the lines of ExprUseVisitor but that's not exactly what we want anyway.

from rust-clippy.

llogiq avatar llogiq commented on May 20, 2024

@Manishearth Now I have a very strange compiler error:

error: duplicate specification of lint shadow_same
error: duplicate specification of lint shadow_reuse
error: duplicate specification of lint shadow_foreign

I'm quite sure I have only one definition of each lint. Perhaps a rustup --channel=nightly will fix it.

from rust-clippy.

birkenfeld avatar birkenfeld commented on May 20, 2024

This comes from get_lints() returning the same lint name(s) for multiple passes.

from rust-clippy.

llogiq avatar llogiq commented on May 20, 2024

Ah, I had registered the lint twice. Thanks, @birkenfeld.

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.