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

Mark std::mem::size_of and std::mem::size_of_val as const function #38772

Closed
mzji opened this issue Jan 2, 2017 · 3 comments
Closed

Mark std::mem::size_of and std::mem::size_of_val as const function #38772

mzji opened this issue Jan 2, 2017 · 3 comments

Comments

@mzji
Copy link

mzji commented Jan 2, 2017

This allows using size_of and size_of_val in constants contexts. Does this need an RFC?

@abonander
Copy link
Contributor

IIRC from the last time this came up, the data used by these intrinsics isn't available until the translation pass, long after const-expansion, and because of things like arrays, where you can use a const fn for the size, it becomes a chicken-or-egg problem. Imagine if you had something like this:

type MyArray = [i32; size_of::<MyArray>];

Of course, you could paper over this by making it an error to do something like this, but that would require an RFC.

@mzji
Copy link
Author

mzji commented Jan 2, 2017

@abonander You are right. If we want to do this, we need to add a constrain to size_of and size_of_val to make them only accept "concrete" types (i.e. types with known size). If it's related to the compilation passes then I think we need to listen to some rustc gurus.

@nagisa
Copy link
Member

nagisa commented Jan 2, 2017

Duplicate of #34078.

@bluss bluss closed this as completed Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants