-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Warn about C-style octal literals #131309
base: master
Are you sure you want to change the base?
Warn about C-style octal literals #131309
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
suspicious_leading_zero
lint for detecting C-style octalsfe17bb5
to
def1383
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
def1383
to
f70a324
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
f70a324
to
e7881ba
Compare
This comment has been minimized.
This comment has been minimized.
e7881ba
to
ea90417
Compare
This comment has been minimized.
This comment has been minimized.
ea90417
to
2bfd5cf
Compare
This comment has been minimized.
This comment has been minimized.
2bfd5cf
to
81b09ce
Compare
The Miri subtree was changed cc @rust-lang/miri |
src/tools/miri/tests/pass-dep/concurrency/tls_pthread_drop_order.rs
Outdated
Show resolved
Hide resolved
81b09ce
to
24e10ba
Compare
This looks fine to me. Let's nominate it for T-lang fcp (which could unfortunatly take months, due to T-lang backlog). I've taken the liberty to adjust the PR description to include the lint description as well, in order to clearly see what the lint does. Feel free to update it if you update the one in the PR. @rustbot labels -S-waiting-on-review +S-waiting-on-team +I-lang-nominated |
Adding easy decision as I expect this to be accepted without much discussion, I was honestly surprised to see that this didn't exist already in rustc. |
Starting a lang FCP for this. @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
I don't know. This still feels maybe more like a clippy lint to me. That is, it seems maybe odd to lint against this in Rust when it's entirely unambiguous in our language, and when I've intentionally written decimals with leading zeros for reasons that are spiritually similar to why we might write hexidecimals or binary literals with leading zeros. Perhaps if we had a |
Uplifts
clippy::zero_prefixed_literal
asleading_zeros_in_decimal_literals
, warn-by-default.The
leading_zeros_in_decimal_literals
lint detects decimal integral literals with leading zeros.Example
Explanation
In some languages (including the infamous C language and most of its family), a leading zero marks an octal constant. In Rust however, a
0o
prefix is used instead.Thus, a leading zero can be confusing for both the writer and a reader.
In Rust:
prints
123
, while in C:prints
83
(as83 == 0o123
while123 == 0o173
).Notes
Compared to the Clippy lint the only difference in behavior is that the suggestion to remove leading zeros from unambiguously decimal literals (those with 8's or 9's in them) is marked as machine-applicable.
So, the current approach thus is:
0o
.Alternative approaches to consider:
Closes #33448
r? @ghost