Add Vec-to-slice coercion extern specs#160
Merged
Merged
Conversation
Specify the postcondition `*result == *vec` for the three ways a `Vec<T>` can be coerced to `&[T]`: `as_slice`, `Deref::deref` (implicit `&v` coercion), and `AsRef::as_ref` (`v.as_ref()`). This lets the refinement checker propagate Seq refinements from Vec through all standard coercion paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013oVufAKCMzsLRnQ8F58PdP
2dc1cc5 to
66f7a4e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends Thrust’s injected std.rs extern specs so the refinement checker can propagate Seq-style refinements through the three common Vec<T> -> &[T] coercion paths (as_slice, Deref, AsRef). It also adds UI coverage for the implicit deref coercion route (&v to &[T]).
Changes:
- Add extern specs for
Vec::as_slice,<Vec<T> as Deref>::deref, and<Vec<T> as AsRef<[T]>>::as_ref, each ensuring*result == *vec. - Add a passing UI test validating slice contents obtained via implicit deref coercion (
let s: &[T] = &v;). - Add a failing UI test that triggers an
Unsatwhen asserting an incorrect element value through the same coercion path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
std.rs |
Adds three extern specs to equate the resulting slice model with the source Vec model for all standard Vec -> &[T] coercions. |
tests/ui/pass/vec_deref.rs |
New passing test covering implicit &Vec<T> → &[T] deref coercion and basic slice property checks. |
tests/ui/fail/vec_deref.rs |
New failing test ensuring the deref coercion path produces an Unsat when asserting an incorrect slice element. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Specifies the postcondition
*result == *vecfor the three standard ways aVec<T>can be coerced to&[T], letting the refinement checker propagate Seq refinements through all of them.Changes
std.rsVec::as_slice: explicit callVec::as_slice(&v)Deref::deref: implicit coercionlet s: &[T] = &vAsRef::as_ref:v.as_ref()All three specs have the postcondition
*result == *vec.Tests
2 new UI tests covering the implicit deref coercion path:
pass/vec_deref.rs&vcoercion; assert len and element valuesfail/vec_deref.rs