Change NonNull::as_uninit_* to take self by value (as opposed to reference), matching primitive pointers. by Raekye · Pull Request #96100 · rust-lang/rust (original) (raw)

Copied from my comment on #75402:

I noticed that as_uninit_* on pointers take self by value (and pointers are Copy), e.g. see as_uninit_mut.

However, on NonNull, these functions take self by reference, e.g. see the function with the same name by for NonNull: as_uninit_mut takes self by mutable reference. Even more inconsistent, as_uninit_slice_mut returns a mutable reference, but takes self by immutable reference.

I think these methods should take self by value for consistency. The returned lifetime is unbounded anyways and not tied to the pointer/NonNull value anyways

I realized the change is trivial (if desired) so here I am creating my first PR. I think it's not a breaking change since (it's on nightly and) NonNull is Copy; all previous usages of these methods taking self by reference should continue to compile. However, it might cause warnings to appear on usages of NonNull::as_uninit_mut, which used to require the the NonNull variable be declared mut, but now it's not necessary.