-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Lint against leading 0 in integer literals #33448
Comments
There are lots of lints in clippy that would most help new rustaceans. If there were a process to move lints to rustc as long as they have proven themselves as non-opinionated and false-positive-free, then a lot of people could start benefiting from clippy's lints. |
One thing speaking against doing this in clippy is that this specific lint needs to be done during parsing, because the ast does not get the string representation of a literal, but only a numeric representation. Clippy would have to use the span to obtain the text and then act on the text. Alternatively the ast could be changed to represent the original text, and ast -> hir lowering could extract the numerical representation. |
I don't see a problem with looking at the span of a literal, so we could well develop the lint in clippy, and move it to rustc later. AFAIR, the core team has expressed they don't want to increase the number of included lints to keep it manageable (and probably also to keep compile time from ballooning 😄). The longer we go without merging lints into rustc, the more I think of clippy as |
Works in clippy. There are a lot of lints in clippy specifically for newcomers and stuff. That was in fact the original scope/goal, but it has expanded since then. Also, zero-setup |
I'm in favor of this being a compile time warning that could be disabled with |
I am going to assume that since this topic has had little discussion for around 3-4 years and the issue still persists (see this playground), that it has been "agreed to by silence". Two locations in the The main questions to answer is: Where should this warning be emitted?
|
@rustbot claim |
A literal like
0111
looks like an octal literal in C, but is actually decimal in Rust (octal would be0o111
). This is a footgun, and so seems like something that could be trivially checked for.(I suppose this could be a "clippy" lint, but that seems like it would lose most of the benefit: it seems to me that most people who encounter this will be just starting out, not invested in running external, third-party commands using nightly.)
The text was updated successfully, but these errors were encountered: