Report precondition violation for <usize as SliceIndex>::get_unchecked in const-eval - #161616
Open
bardiharborow wants to merge 1 commit into
Open
Conversation
Collaborator
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
<usize as SliceIndex>::get_unchecked in const-eval<usize as SliceIndex>::get_unchecked in const-eval
teor2345
approved these changes
Aug 24, 2026
Collaborator
|
Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri |
RalfJung
reviewed
Sep 5, 2026
Member
|
@bors squash |
This comment has been minimized.
This comment has been minimized.
…ed` in const-eval * Add a test for the diagnostics on `<usize as SliceIndex>::get_unchecked` in const-eval * Report a precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval The precondition check was gated on `check_language_ub`, which is disabled in const-eval and Miri, on the grounds that the `assume` below it is language UB that the interpreter will catch anyway. It does catch it, but only as "`assume` called with `false`", which says nothing about what the caller did wrong. This commit instead gates the check on `check_library_ub`, matching `get_unchecked_mut`, so that the interpreter reports the violated precondition. * fixup! Report a precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval * tweak comment Co-authored-by: Ralf Jung <post@ralfj.de>
Contributor
|
🔨 4 commits were squashed into 3974528. |
rust-bors
Bot
force-pushed
the
get-unchecked-index-precondition-const-eval
branch
from
September 5, 2026 07:33
2a40480 to
3974528
Compare
Member
|
Makes sense, thanks :) |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 5, 2026
…precondition-const-eval, r=RalfJung Report precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval The precondition check was gated on `check_language_ub`, which is disabled in const-eval and Miri, on the grounds that the `assume` below it is language UB that the interpreter will catch anyway. It does catch it, but only as "`assume` called with `false`", which says nothing about what the caller did wrong. This PR instead gates the check on `check_library_ub`, matching `get_unchecked_mut`, so that the interpreter reports the violated precondition. Fixes rust-lang#161611
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The precondition check was gated on
check_language_ub, which is disabled in const-eval and Miri, on the grounds that theassumebelow it is language UB that the interpreter will catch anyway. It does catch it, but only as "assumecalled withfalse", which says nothing about what the caller did wrong.This PR instead gates the check on
check_library_ub, matchingget_unchecked_mut, so that the interpreter reports the violated precondition.Fixes #161611
@rustbot label +A-const-eval +A-diagnostics +A-slice +T-libs +requires-nightly