-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Warn about C-style octal literals #131309
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
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 |
Does an allow-by-default rustc lint has better discoverability than a warn-by-default clippy lint? |
@rfcbot reviewed |
@rfcbot concern allow-by-default Per @joshtriplett's comment, the FCP has changed to allow-by-default, but the OP on the PR (and afaik the impl) is still warn-by-default. Filing this concern until those are updated. |
Regarding the lint, I think my ideal would probably be to have this lint as allow-by-default and a more narrowly targeted one as allow-by-default, with a "subtyping" relationship -- I guess this means a |
☔ The latest upstream changes (presumably #136070) made this pull request unmergeable. Please resolve the merge conflicts. |
eacb589
to
b410dcc
Compare
☔ The latest upstream changes (presumably #127541) made this pull request unmergeable. Please resolve the merge conflicts. |
ea5f5d5
to
4785d88
Compare
This comment has been minimized.
This comment has been minimized.
4785d88
to
2dd2905
Compare
☔ The latest upstream changes (presumably #137348) made this pull request unmergeable. Please resolve the merge conflicts. |
2dd2905
to
aa3f85b
Compare
This comment has been minimized.
This comment has been minimized.
aa3f85b
to
b9de4a6
Compare
☔ The latest upstream changes (presumably #137752) made this pull request unmergeable. Please resolve the merge conflicts. |
b9de4a6
to
f41dbfa
Compare
☔ The latest upstream changes (presumably #138761) made this pull request unmergeable. Please resolve the merge conflicts. |
f41dbfa
to
e004aff
Compare
☔ The latest upstream changes (presumably #119220) made this pull request unmergeable. Please resolve the merge conflicts. |
e004aff
to
15a539a
Compare
☔ The latest upstream changes (presumably #139983) made this pull request unmergeable. Please resolve the merge conflicts. |
15a539a
to
c724951
Compare
+1 for a narrowly-scoped lint that only fires on patterns that look like file modes and other very common uses of octal. For that I think the upside (likelihood times benefit) of finding bugs far exceeds the downside (likelihood times inconvenience) of adding a blanket allow if a false positive slaps you and you don't like it. I don't see why we would also have an allow-by-default lint that blanket warns on leading zeros. If we have the narrowly scoped version, that starts to sound more like a clippy lint in the style category. |
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, this will not warn if the literal is unambiguous, i.e. it has 8's or 9's in it (clearly not octal) or it is <10 (in this case the value does not depend on the base).
Closes #33448
r? @ghost