Add assert_zst
intrinsic for use in mem::conjure_zst
function
#147287
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.
Implementation as I described in this comment: #146479 (comment)
Which states that this should be a hard error for concrete types, but not for generic types. Since the compiler already has multiple assertions like this, this should be reasonable.
Note that
mem::conjure_zst
is being written concurrently in #146479, but since this is just adding an intrinsic, it should be fine to merge independently. The tracking issue for the function is #95383.Notes for review:
assert_inhabited
since this does that as well, although it feels better to just do both the inhabitedness and size check under the same intrinsic rather than requiring both to be called, since the codegen will be a bit easier that way. (only one layout query, instead of two)assert_inhabited
in the code to determine what would need to be modified. I'm not sure if the string-based checks under miri a 8000 nd rust-analyzer need to be modified right now, but since this PR will ping both those teams, I'm sure they will tell me whether I should keep it or remove it if it matters.conjure_zst
in the error message (attempted to conjure type{}
when it is not zero-sized). If the name gets changed before stabilisation, we probably want to change the error message here too.unsafe fn
for creating a ZST libs-team#292 (comment) because this just compiles into a panic, but the lint works differently. So, this will require an additional follow-up PR modifying theinvalid_value
lint to also trigger in this case.cc @scottmcm who proposed the original
conjure_zst
intrinsic; you can decide whether you want to actually do the review for this or not.