I'm surprised how little a Google search turns up for them; the best I found was a mention (but no description or examples) in docs.rs: https://docs.rs/rustc-ap-syntax_pos/634.0.0/rustc_ap_syntax_...
Do these enforce against out-of-bounds values by panicking, the way arrays do? Or are they unsafe?
See https://github.com/rust-lang/rust/blob/master/library/core/s...
They are unsafe. The safe API of your type must prevent constructing invalid values.
It is trivial to create an integer type in Rust that only accepts certain values, and doing so doesn't require these hints, e.g.,
#[bounded_int(start, end)]
struct MyBoundedInt(i32);
creates a type called MyBoundedInt that never will take a value outside the range [start, end); this can be proved formally, i.e., there is no safe Rust program that can violate that. No need to run any kind of verification on top.The place where Rust differs from Ada, and the reason I use these attributes, is to enable the layout optimizations that Rust performs (e.g. Option<NonZero> having the same size in bytes as NonZero, and many others).
From the Rust reference (https://doc.rust-lang.org/reference/influences.html):
> Rust is not a particularly original language, with design elements coming from a wide range of sources. Some of these are listed below ...
Oh, I did not mean to suggest that Rust does, just some people do, because they are not familiar with other programming languages and whatnot.
Like, have literally a project with almost 100k LOC which is all built on top of this.