-
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
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 |
I feel that targeting this lint specifically at unix permission bits would make sense -- something like `0[0-7][0-7][0-7]`.
…On Tue, Jan 14, 2025, at 1:53 AM, Josh Triplett wrote:
@traviscross <https://github.com/traviscross> I can appreciate that. On the other hand, UNIX is the gift that keeps on giving, and octal lives on in permission bits, file modes, and (as a consequence) Git repository internals, among other places. Because of that, octal remains *just* common enough to be a potential hazard.
If the consequence is that we need to write one `allow` if we actually *want* to use leading zeroes (or switch to using leading spaces with a `rustfmt::skip`), that seems reasonable. The failure mode of "my personal style produces a warning and I need to change it or add an `allow`" seems less hazardous than the failure mode of "my permissions are wrong in a way that's extremely difficult to spot when looking at the code".
—
Reply to this email directly, view it on GitHub <#131309 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABF4ZSB7CZ2Q35Y2HFEJ2L2KSX6JAVCNFSM6AAAAABPNXCQFGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBZGE3DCMRVGQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
To be honest you could probably go even narrower, like `0[75310][75310][75310]` or something. I feel like the vast majority of bits are something like `0755` and not arbitrary combinations. I think users would appreciate a narrowly tailored lint that can explain exactly why it is triggering.
…On Tue, Jan 14, 2025, at 5:24 AM, Niko Matsakis wrote:
I feel that targeting this lint specifically at unix permission bits would make sense -- something like `0[0-7][0-7][0-7]`.
On Tue, Jan 14, 2025, at 1:53 AM, Josh Triplett wrote:
>
>
> @traviscross <https://github.com/traviscross> I can appreciate that. On the other hand, UNIX is the gift that keeps on giving, and octal lives on in permission bits, file modes, and (as a consequence) Git repository internals, among other places. Because of that, octal remains *just* common enough to be a potential hazard.
>
> If the consequence is that we need to write one `allow` if we actually *want* to use leading zeroes (or switch to using leading spaces with a `rustfmt::skip`), that seems reasonable. The failure mode of "my personal style produces a warning and I need to change it or add an `allow`" seems less hazardous than the failure mode of "my permissions are wrong in a way that's extremely difficult to spot when looking at the code".
>
>
>
> —
> Reply to this email directly, view it on GitHub <#131309 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABF4ZSB7CZ2Q35Y2HFEJ2L2KSX6JAVCNFSM6AAAAABPNXCQFGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBZGE3DCMRVGQ>.
> You are receiving this because you were mentioned.Message ID: ***@***.***>
>
>
|
077 is also likely to be permissions, and 0100644 is likely to be a file mode. |
c3305be
to
eacb589
Compare
So, proposal: I think we should do two separate FCPs here. First, let's do an FCP for approving the lint, as allow-by-default. Then, separately, we can work on consensus for making it warn. |
I'm ok with the lint, but as an alternative, I think a lint described as detecting "unix file permissions and modes" (vs any use of leading 0) might be a better framing that would be more likely to be warn-by-default.
…On Tue, Jan 14, 2025, at 8:26 AM, Josh Triplett wrote:
So, proposal:
I think we should do two separate FCPs here. First, let's do an FCP for approving the lint, as allow-by-default. Then, separately, we can work on consensus for making it warn.
—
Reply to this email directly, view it on GitHub <#131309 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABF4ZSNDG4B7WVZDH7NPZT2KUGBLAVCNFSM6AAAAABPNXCQFGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBZHEYDONJYGQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Could @rust-lang/lang folks who don't object to having the lint as allow-by-default please check a box at #131309 (comment) ? When that's done we can do a separate PR and FCP for whether to warn by default, either with the current lint or one with additional scope reduction to specific number lengths. |
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
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