2 ms·
Wow, I did not know about those! 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
by brundolf 6y ago
Wow, I did not know about those!
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_pos/symbol/sym/constant.rustc_layout_scalar_valid_range_start.html 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?
- jleahy 6y agoThey're not only unsafe, but as far as I'm aware they're a compiler implementation detail that isn't really supposed to be used in user code (along with rustc_nonnull_optimization_guaranteed). It's actually how NonZero is implemented. See https://github.com/rust-lang/rust/blob/master/library/core/src/num/nonzero.rs https://github.com/rust-lang/rust/blob/master/library/core/s...
- brundolf 6y agoAh, that explains things
- tmzt 6y agoIt would be nice to have a #[range(a..b)] version of this that could be standardized.
- volta83 6y ago> Or are they unsafe? They are unsafe. The safe API of your type must prevent constructing invalid values.