-
Notifications
You must be signed in to change notification settings - Fork 104
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
Use compile-time assertions to deny ZSTy DSTs #1154
Conversation
src/util.rs
Outdated
const DST_IS_NOT_ZST: bool = { | ||
assert!(!Self::DST_IS_ZST); | ||
!Self::DST_IS_ZST | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we just do this based on the existing KnownLayout::LAYOUT
const rather than introducing new machinery in KnownLayout
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
024c37a
to
e4c0450
Compare
0b22ac7
to
d3c2576
Compare
/// | ||
/// # Compile-Time Assertions | ||
/// | ||
/// This method cannot yet be used on unsized types whose dynamically-sized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This method cannot yet be used on unsized types whose dynamically-sized | |
/// This method cannot be used on unsized types whose dynamically-sized |
IMO we shouldn't imply that we'll lift this restriction in the future. We might, but it's not guaranteed, and it's also pointless cognitive burden for users to think about our long-term plans when there's no specific timeline and so there's no meaningful difference between "you can't yet" and "you can't."
Same elsewhere in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want folks relying on this function as a compile-time assert on DST ZSTiness so the "yet" is load-bearing.
Presently, we deny ZSTy DSTs in our APIs via panicking at runtime. However, the ZSTiness of a DST is statically detectable and can be denied instead at compile time. This PR replaces our ZSTy DST panics with compile-time assertions. Doing gives us the freedom later provide meaningful runtime semantics in such cases. Partially addresses #325 Closes #1149
Presently, we deny ZSTy DSTs in our APIs via panicking at runtime. However, the ZSTiness of a DST is statically detectable and can be denied instead at compile time. This PR replaces our ZSTy DST panics with compile-time assertions. Doing gives us the freedom later provide meaningful runtime semantics in such cases.
Partially addresses #325
Closes #1149