make size_of_val and align_of_val const fns #50559
make size_of_val and align_of_val const fns #50559Gankra wants to merge 2 commits intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
| #[inline] | ||
| #[stable(feature = "rust1", since = "1.0.0")] | ||
| #[cfg(not(stage0))] | ||
| pub const fn size_of_val<T: ?Sized>(val: &T) -> usize { |
There was a problem hiding this comment.
If you want this PR to go through fast, you should be marking the function with #[rustc_const_unstable(feature = "const_size_of_val")] (and create a tracking issue)
| assert_eq!(&EMPTY, b""); | ||
|
|
||
| // ~ one day ~ | ||
| // static SIZE_OF_OWO_SLICE: usize = size_of_val(&OWO[..]); |
There was a problem hiding this comment.
you should be able to write
static FOO: &[u8] = &OWO;
static BAR: usize = size_of_val(FOO);because coercions don't need method calls like slice indexing does
|
I've 👎'ed this PR due to #46571 (comment) |
|
tagging @rust-lang/lang because making this const fn would complicate future language changes. |
|
Closing in favour of #50579 which I will use to make slice.len() const. |
Closes #46571