-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make size_of_val and align_of_val const fns #50559
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 |
@@ -338,6 +338,34 @@ pub const fn size_of<T>() -> usize { | |||
/// ``` | |||
#[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_eq!(&EMPTY, b""); | ||
|
||
// ~ one day ~ | ||
// static SIZE_OF_OWO_SLICE: usize = size_of_val(&OWO[..]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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