-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Range types for integers (or refinement types?) #19801
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
Comments
@BryanQuigley Thanks for your comments! As this is a non-trivial change to the language, I suggest that you open a discussion on http://discuss.rust-lang.org/ and see what people think. If the idea gains traction, you could write an RFC for it. |
Ada has this. It would be great in Rust, as we're going for the same niche of low-level + high-assurance. I wonder though if we should go for a more general system, such as refinement types or pre/post-conditions. There have been a number of successes bolting these onto languages like Haskell, F#, and C#. AIUI, they manage this without heavy changes to the core language. The condition checker is a mostly-separate tool that gathers proof obligations from the source code and passes them to a SMT solver. Basically I think this is an area where we should give researchers and other interested parties some time to experiment before we standardize something into Rust itself. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#671 |
It seems like a natural extension of how variables (immutable by default, mutable if specified) are defined to allow the programmer to dictate a specific range of allowed values for an integer. If I know a value is only valid between 0-1000 the sooner I declare that the better it is for catching bugs, off by one errors, and more...
I'm not sure what exact syntax would work, maybe:
x is only valid from 0-1000 inclusive.
(Apologies if this is already possible, I've been parsing the docs trying to learn Rust.)
The text was updated successfully, but these errors were encountered: