Lint against iterator functions that panic when N is zero #153563
Lint against iterator functions that panic when N is zero #153563Urgau wants to merge 4 commits into
N is zero #153563Conversation
|
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 |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
|
This seems like clearly worth linting, under the usual intent of "we should lint anything that will always panic if reached". Not this PR and not this FCP: I would love to see attributes like this move into the diagnostics namespace to let more things be self-serve for libraries to get lints. If we could no longer need lints like https://rust-lang.github.io/rust-clippy/stable/index.html?search=step_#iterator_step_by_zero because the definition of |
|
@scottmcm 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. |
|
Makes sense to me. It's important that it not lint the @rfcbot reviewed |
This comment was marked as resolved.
This comment was marked as resolved.
7b7975d to
93b8cf2
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. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
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]↩