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

Static asserts #1146

Closed
nikomatsakis opened this issue Jun 2, 2015 · 4 comments
Closed

Static asserts #1146

nikomatsakis opened this issue Jun 2, 2015 · 4 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@nikomatsakis
Copy link
Contributor

It would be useful to be able to specify static expressions which must be evaluated to true or else compilation will fail. This can be particularly useful in checking assumptions that are baked into unsafe code, such as that the size of two structs is equal.

Relevant RFCs:

@nrc nrc added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 29, 2016
@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

The only thing needed to get this working is rust-lang/rust#51999 so I am closing this in favor of that issue.

@Centril Centril closed this as completed Oct 7, 2018
@DoumanAsh
Copy link

@Centril Small question because I have use case for static_assert outside of const fn, there is no plan to have static assertion outside of const fn context?

@Centril
Copy link
Contributor

Centril commented Dec 5, 2018

@DoumanAsh With #2526 you can define const _ = $expr;. That way, you can statically assert things outside a const fn.

@Serentty
Copy link

@Centril It seems to me like it would still be useful to have a few macros in the standard library simply for easy of reading, and to make it look more like a “feature” instead of a “pattern”. It would be nice to have visual clarity for something like ensuring that a type implements a trait. I really like what static_assertions has done, and think that with const panicks, it could be cleaned up, improved, and standardized, all without adding any language features, just standard library ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants