Lint against iterator functions that panic when N is zero - #153563
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to the CTFE machinery Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_attr_parsing |
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
ff233d2 to
44380ea
Compare
This seems to do much more than that. It adds a new language primitive, a new kind of built-in assertion. Could you motivate that? |
The code is unfortunately tangled, it doesn't add a new language primitive per se, but I could probably modify that function so it doesn't take an |
|
Given that |
44380ea to
36de202
Compare
|
Understandable, I've reworked the PR to avoid touching at |
There was a problem hiding this comment.
I love the idea but it should better for someone more familiar with this topic other than me to review. @RalfJung Could you take over? Otherwise I'd reroll.
|
I'm afraid not, I don't have capacity at the moment. @rustbot reroll |
This comment has been minimized.
This comment has been minimized.
36de202 to
0a8cacf
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I think the overall idea is good and I could see myself approving down the line, however I think we should see if we can have an attribute on the generic parameter itself instead of applying rustc_panics_when_n_is_zero to the enclosing function. If not, I'd still want something more verbose, such as #[rustc_panics_when_const_param_is_zero(N)]
I don't think this should be touching AssertLint. I feel like it might be simpler to just add a separate error for this rather than using existing mechanisms.
0a8cacf to
d033014
Compare
This comment has been minimized.
This comment has been minimized.
|
I had to add the encoding of const-params in I've also removed any interaction with @rustbot ready |
|
overall looks good, would like someone else to sign off with me on this together though @rustbot reroll |
|
r? compiler |
|
@fee1-dead also approved it in this comment. @bors r=fee1-dead,ShoyuVanilla |
…r=fee1-dead,ShoyuVanilla Lint against iterator functions that panic when `N` is zero This PR extends the deny-by-default `unconditional_panic` lint, by linting on iterator functions that panics when `N` (chunks/windows size) is zero[^attr]. Those methods are [documented](https://doc.rust-lang.org/std/primitive.slice.html#panics-11) to panic if `N` is zero. ``` error: this operation will panic at runtime --> $DIR/const-n-is-zero.rs:11:13 | LL | let _ = s.array_windows::<0>(); | ^^^^^^^^^^^^^^^^^^^^^^ const parameter `N` is zero | = note: `#[deny(unconditional_panic)]` on by default ``` cc @rust-lang/libs-api [^attr]: this is done by introducing a new internal attribute on the const parameter: `#[rustc_panics_when_zero]`
|
💔 I suspect this PR failed tests as part of a rollup After fixing the problem, consider running a try job for the failed job before re-approving. Link to failure: https://github.com/rust-lang/rust/actions/runs/30255157007/job/89942047433?pr=160002 |
|
This pull request was unapproved. This PR was contained in a rollup (#160002), which was unapproved. |
93b8cf2 to
24e4698
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r=fee1-dead,ShoyuVanilla |
Rollup of 9 pull requests Successful merges: - #153563 (Lint against iterator functions that panic when `N` is zero ) - #159960 (Allow `UnsafeCell` content access without `get` in `invalid_reference_casting` lint) - #158893 (Clarify preconditions of raw size/align methods) - #159220 (Don't optimize across storage markers in SimplifyComparisonIntegral) - #159309 (Move tests batch 18) - #159450 (Add codegen test for enum clone) - #160017 (Make BorrowSet methods public again) - #160022 (Refactor rustc_hir re-exports) - #160041 (Correct tracking issue for `casefold` feature)
Rollup merge of #153563 - Urgau:lint-panics-when-n-is-zero, r=fee1-dead,ShoyuVanilla Lint against iterator functions that panic when `N` is zero This PR extends the deny-by-default `unconditional_panic` lint, by linting on iterator functions that panics when `N` (chunks/windows size) is zero[^attr]. Those methods are [documented](https://doc.rust-lang.org/std/primitive.slice.html#panics-11) to panic if `N` is zero. ``` error: this operation will panic at runtime --> $DIR/const-n-is-zero.rs:11:13 | LL | let _ = s.array_windows::<0>(); | ^^^^^^^^^^^^^^^^^^^^^^ const parameter `N` is zero | = note: `#[deny(unconditional_panic)]` on by default ``` cc @rust-lang/libs-api [^attr]: this is done by introducing a new internal attribute on the const parameter: `#[rustc_panics_when_zero]`
View all comments
This PR extends the deny-by-default
unconditional_paniclint, by linting on iterator functions that panics whenN(chunks/windows size) is zero1.Those methods are documented to panic if
Nis zero.cc @rust-lang/libs-api
Footnotes
this is done by introducing a new internal attribute on the const parameter:
#[rustc_panics_when_zero]↩