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

size_of cannot be called outside of a function #6320

Closed
dymk opened this issue May 8, 2013 · 6 comments
Closed

size_of cannot be called outside of a function #6320

dymk opened this issue May 8, 2013 · 6 comments
Labels
P-low Low priority

Comments

@dymk
Copy link

dymk commented May 8, 2013

I realize this isn't an issue that can be fixed by changing the definition of sys::size_of, however it seems like Rust (like any systems programming language) should have a mechanism for determining the size of a type.

a-la:

pub type MyType = u32;
// Couldn't really be done like this, but you get the idea
pub static MyTypeBits = sys::sizeof::<MyType>() * 8; 

Could be implemented with a macro? Something like size_of!(MyType).

@thestinger
Copy link
Contributor

It can't be implemented as a macro or syntax extension, because they have no knowledge of types. They just generate an AST.

@catamorphism
Copy link
Contributor

Not sure what changes would need to be made to make this work, but as it would likely entail changing the constant language, nominating for milestone 1, well-defined

@catamorphism
Copy link
Contributor

Accepted for milestone 1, well-defined

@pcwalton
Copy link
Contributor

Nominating as I believe this is totally out of scope for 1.0.

@pnkfelix
Copy link
Member

We are probably not going to get to this for 1.0; we've reserved the sizeof keyword so we should be able to put something in post-1.0.

@thestinger
Copy link
Contributor

Extending constant expressions or adding CTFE would need to go through an RFC, and I don't think there's consensus for adding an ever increasing number of special cases (like size_of, align_of and friends). It's sad that Rust can't do this, but it's not a backwards compatibility risk, it's not a bug and a good solution is unclear - not bug tracker material.

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 20, 2020
…ge_contains_using_float, r=llogiq

Fix suggestion in `manual_range_contains` when using float

Fix rust-lang#6315

changelog: Fix suggestion in `manual_range_contains` when using float
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-low Low priority
Projects
None yet
Development

No branches or pull requests

5 participants