Skip to content
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

Add MapWindows compile fail check for N=0 #121156

Closed

Conversation

Nydauron
Copy link

@Nydauron Nydauron commented Feb 15, 2024

Related to issue #87155. Adds a constant assertion to MapWindows to check if generic N, representing the size of the window array, is not zero. Before, a zero-length window array would cause MapWindows to panic at runtime. With the const assert, if N=0, the code will not compile.

A map window test that dealt with a zero-width array is moved to the Iterator::map_windows doc-tests in order to check for compilation failure. Before this change, the test was meant to panic.

Checks if const generic N is not set to 0, otherwise it prevents
compilation.
@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 15, 2024
@Nydauron Nydauron changed the title Add MapWindow compile fail check for N=0 Add MapWindows compile fail check for N=0 Feb 15, 2024
@the8472
Copy link
Member

the8472 commented Feb 15, 2024

We do want something like this in various places such as slice::array_chunks. The issue is that we currently lack language features to express this properly in the type system or avoiding post-monomorphization errors when users call it from code that is generic over N.

We need some combination of const if, const generic expressions or pattern types to make this work properly.

@Mark-Simulacrum
Copy link
Member

r? @the8472 since it sounds like you have more context here. Failing that this is probably T-libs-api (though it's unstable so maybe not strictly required).

@rustbot rustbot assigned the8472 and unassigned Mark-Simulacrum Feb 17, 2024
@Mark-Simulacrum Mark-Simulacrum added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 17, 2024
@the8472
Copy link
Member

the8472 commented Feb 29, 2024

Context, previous PRs that tried to do something similar and were rejected because we currently lack the language features to make this ergonomic for users:

Stabilization of various features is also blocked or at least less likely until we have a better solution:

So for now I'll close this until some progress gets made on the questions in those issues.

@the8472 the8472 closed this Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants