Constier maybe uninit by usbalbin · Pull Request #79621 · rust-lang/rust (original) (raw)
Thanks a lot for the PR, @usbalbin. :) Yes this is certainly in the right direction.
Also any ideas for name of the feature gate? I guess const_maybe_assume_init is quite misleading since I have added some more methods.
You are doing many things at once here, that IMO should have different feature gates. Maybe as a start it'd make more sense to restrict the PR to just the assume_init
method(s).
Should I add test? If so what should be tested?
Is there even a way to use assume_init
correctly given the current CTFE limitations? I think that will require mutable references; I am not sure what the status of this is.
A simple smoke test would be something like
const TRUE: bool = { let mut x = MaybeUninit::::uninit(); x.as_mut_ptr().write(true); x.assume_init() }; assert!(TRUE);
And also a compile-fail test like
const BAD: () = { MaybeUninit::<!>::uninit().assume_init(); }