Skip to content

Lint for misleading indentation #10483

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

Closed
glaebhoerl opened this issue Nov 14, 2013 · 3 comments
Closed

Lint for misleading indentation #10483

glaebhoerl opened this issue Nov 14, 2013 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@glaebhoerl
Copy link
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.

@emberian
Copy link
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
Copy link
Member

emberian commented Apr 7, 2014

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
Copy link
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

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 24, 2023
New lint to detect `&std::path::MAIN_SEPARATOR.to_string()`

Fixes rust-lang#10480

changelog: [`manual_main_separator_str`] new lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

3 participants