Stream: general

Topic: Potential stabilization of valid_range attributes


Elichai Turkel (Apr 07 2020 at 07:49, on Zulip):

Hi,
I think rustc_layout_scalar_valid_range_start, rustc_layout_scalar_valid_range_end, rustc_nonnull_optimization_guaranteed have proved themselves quite useful and a clever use of rust's safety guarantees.
I think these(probably under different names?) can be of great service to users/libraries outside of libcore too.
And because they require unsafe to write into the object I think they won't be too easily misused.
for example, I can Imagine NonNegative i32 being used quite often, and will have more than 1 bit for niche.

Would love to hear what do people think and if the strong wording against this being ever stabilized are just because it's a rustc attribute or for some other/deeper reason.

Amanieu (Apr 07 2020 at 13:35, on Zulip):

I feel that this functionality is better exposed with const generics than attributes. It would essentially be an expanded version of NonZero.

Elichai Turkel (Apr 07 2020 at 18:25, on Zulip):

Hmm sounds interesting, how would that look like?

Josh Triplett (Apr 08 2020 at 04:34, on Zulip):

I found myself wanting this as well, recently. I have some large data structures that could be optimized by creating specialized types that have large niches.

Lokathor (Apr 08 2020 at 07:35, on Zulip):

How far is const generics from being ready for stable? How far is this set of attributes from being something that could be ready for stable? Probably, attributes would be a lot more practical a lot sooner.

Amanieu (Apr 08 2020 at 12:36, on Zulip):

RangeU32<min: u32, max: u32>

Jake Goulding (Apr 08 2020 at 13:46, on Zulip):

See also https://github.com/rust-lang/rfcs/pull/2888

Last update: May 29 2020 at 17:55UTC