Skip to content

Lint for misleading indentation #10483

@glaebhoerl

Description

@glaebhoerl
Contributor

While working in C++, I was recently bitten by having accidentally omitted the closing brace of one if-else statement among many others. The compiler only complained of a syntax error many lines lower down at the beginning of the next function, and it took me a while to find where the problem was, because visually, I normally interpret code by looking at indentation, which matched my intent. On the other hand, the compiler ignores indentation and looks only at braces, which did not match my intent. In this case I got a compile error, but in other cases bad indentation can cause a human to derive a different meaning when reading (syntactically well-formed) code than the compiler does, leading to bugs.

This is the drawback of whitespace-irrelevant syntax: the programmer has to encode the same information in two separate ways, introducing more opportunities to make mistakes. We could have a lint which complains if the "logical" and visual indentations of code don't align to help catch these kind of problems.

Activity

emberian

emberian commented on Nov 14, 2013

@emberian
Member

We solve the if-else problem by always requiring braces, but this would still be useful. Not sure it should really be a lint, it feels like something a rustfmt tool would do.

emberian

emberian commented on Apr 7, 2014

@emberian
Member

This is a very difficult thing to implement in librustc, since indentation is not information that is preserved. The lint would still be useful.

steveklabnik

steveklabnik commented on Jan 21, 2015

@steveklabnik
Member

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#630

added a commit that references this issue on Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@emberian@glaebhoerl

        Issue actions

          Lint for misleading indentation · Issue #10483 · rust-lang/rust