Skip to content
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

Calling std::mem::size_of::<T> in a generic constexpr context errors. #45598

Closed
mystor opened this issue Oct 28, 2017 · 2 comments
Closed

Calling std::mem::size_of::<T> in a generic constexpr context errors. #45598

mystor opened this issue Oct 28, 2017 · 2 comments
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. I-compiletime Issue: Problems and improvements with respect to compile times.

Comments

@mystor
Copy link
Contributor

mystor commented Oct 28, 2017

This code fails to build right now, while it should succeed (as std::mem::size_of::<T> is const):

use std::mem;
use std::marker::PhantomData;
struct U<T>([u8; mem::size_of::<T>()], PhantomData<T>);
fn main() {}
@mystor
Copy link
Contributor Author

mystor commented Oct 28, 2017

   Compiling playground v0.0.1 (file:///playground)
error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
 --> src/main.rs:3:18
  |
3 | struct U<T>([u8; mem::size_of::<T>()], PhantomData<T>);
  |                  ^^^^^^^^^^^^^^^^^ `T` does not have a constant size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `T`
  = help: consider adding a `where T: std::marker::Sized` bound
  = note: required by `std::mem::size_of`

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

@frewsxcv frewsxcv added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. I-compiletime Issue: Problems and improvements with respect to compile times. labels Oct 28, 2017
@frewsxcv
Copy link
Member

Duplicate of #43408?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. I-compiletime Issue: Problems and improvements with respect to compile times.
Projects
None yet
Development

No branches or pull requests

2 participants