-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Integer fallback still somewhat present? #15201
Comments
cc @pcwalton |
Assigning 1.0, P-backcompat-lang. |
Another (simpler) example: fn main() {
println!("{}", std::mem::size_of_val(&1)); // prints 8 (assumes `int`?)
println!("{}", std::mem::size_of_val(&1.0)); // prints 8 (assumes `f64`?)
} |
Why is this desirable? Sorry, I'm new to Rust, and I like everything I've learned so far, but this comes off as a severe antifeature to me. Adding "i" to all my |
@alexchandel: rust-lang/rfcs#115
The |
My mistake, I forgot about cases like x32 and was assuming equal widths for integer and addressing registers. But the points remains, no? There are cases where a programmer may want the size of the floating point or integer registers of the target platform (and no larger) for speed considerations, or where it's reasonable to assume a signedness, or where one simply doesn't care about the size. Why force a minimal cruft-level when there is a reasonable, defined, default case? |
You can't avoid thinking about the size if you're writing correct code. If you're not using a big integer, you need to verify that it's not going to overflow. |
What about for cases where overflow can't occur? Alternatively, the compiler could have a lint check that warns whenever |
The type that's chosen needs to be large enough for the use case. As I said, if you're not using a big integer, you need to verify that it's not going to overflow. |
Right, so for any target, the size of |
I don't understand the point you're trying to make.
I didn't say the only use case was for storing addresses:
It's unlikely to be the right choice for other use cases. If you're sure that a 32-bit integer is the minimum requirement, that's what you should use. |
floating point numbers for real. This will break code that looks like: let mut x = 0; while ... { x += 1; } println!("{}", x); Change that code to: let mut x = 0i; while ... { x += 1; } println!("{}", x); Closes rust-lang#15201. [breaking-change]
…excrichton This will break code that looks like: let mut x = 0; while ... { x += 1; } println!("{}", x); Change that code to: let mut x = 0i; while ... { x += 1; } println!("{}", x); Closes #15201. [breaking-change] r? @alexcrichton
@thestinger Hmm I think you've convinced me, thanks. |
The type of
a
is never mentioned, so it seems to be assumingint
?Nominating.
The text was updated successfully, but these errors were encountered: