rust-lang / wg-allocators

Home of the Allocators working group: Paving a path for a standard set of allocator traits to be used in collections!
http://bit.ly/hello-wg-allocators
205 stars 9 forks source link

Move `Layout` and `LayoutErr` to `core::mem` #59

Closed TimDiekmann closed 4 years ago

TimDiekmann commented 4 years ago

Layout is basically a wrapper around mem::size_of and mem::align_of (batteries included) and should live in the same module. For compatibility, Layout (and its Error) have to be reexported to core::alloc.

NB: As the discussion just came up (#57), it would also be possible to rename LayoutErr to LayoutError in core::mem and reexport it in core::alloc as LayoutErr.

SimonSapin commented 4 years ago

@rust-lang/libs Any thoughts on this, since it’s about stable APIs?

LukasKalbertodt commented 4 years ago

Adding those two types to core::mem makes sense to me!

Regarding renaming to LayoutError: I'd be uncomfortable with having the same type being available with two different names. I see two viable options:

TimDiekmann commented 4 years ago

Regarding renaming to AllocError: I'd be uncomfortable with having the same type being available with two different names.

I think you meant LayoutError?

When deprecating core::alloc::LayoutErr is an option, why even reexport as core::alloc::LayoutError? Should the reexport of Layout also be marked as deprecated?

This works fine:

#[stable(feature = "alloc_layout", since = "1.28.0")]
#[rustc_deprecated(since = "1.45.0", reason = "Use `core::mem::Layout` instead")]
pub use crate::mem::Layout;

#[stable(feature = "alloc_layout", since = "1.28.0")]
#[rustc_deprecated(since = "1.45.0", reason = "Use `core::mem::LayoutError` instead")]
pub use crate::mem::LayoutError as LayoutErr;

At least it compiles. I tried to build the docs but x.py decided to recompile LLVM which will take a while...

LukasKalbertodt commented 4 years ago

I think you meant LayoutError?

Oh, yes, sorry. Fixed.

TimDiekmann commented 4 years ago

Which #[stable] attribute core::mem::Layout should receive? since = "1.45.0"? While it's confusing, that Layout is introduced in "1.45" it would not compile on older versions.

TimDiekmann commented 4 years ago

Neither #[rustc_deprecated] nor documenting a reexport is working. #[rustc_deprecated] does not emit any warning and neither generate any hints in the documentation. The best bet is to use #[doc(no_inline)] to express that this is a reexport. Maybe we could (soft-)deprecate it later when rustc/rustdoc supports this.