-
Notifications
You must be signed in to change notification settings - Fork 700
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
Remove as
casts.
#2562
base: main
Are you sure you want to change the base?
Remove as
casts.
#2562
Conversation
Can you elaborate on why is this useful? This seems less legible and as long as the as behavior is well defined which afaiui it is, I'm not sure it's worth doing this. |
I don't think casting between |
https://doc.rust-lang.org/reference/expressions/operator-expr.html#numeric-cast looks pretty well defined to me? So it saturates on truncation and zero/sign-extends properly. |
I mean, yes, it is clearly defined that integers are truncated, but that's not necessarily what we want.
Pretty sure integers don't saturate on truncation, otherwise something like this would be true: assert_eq!(100000u32 as u16, u16::MAX); |
I agree that |
Most of these are effectively impossible that they fail in any reasonable platform. I don't think |
Probably all of these are impossible on reasonable platforms. This just makes it obvious if that isn't actually the case anymore, e.g. due to refactoring/updating a dependency.
Oh right, |
This is not possible even on several un reasonable platforms. There is nothing in the standard explicitly forbidding |
☔ The latest upstream changes (presumably 5ff913a) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
I am always a fan of removing as
in favor of try_into
, even if the error is extremely unlikely to happen.
I don't think that the expect
messages add that much compared to unwrap()
. Unwrapping already tells you that there is an integer conversion issue and points to the line, not much to gain for the extra effort of writing down the exact types in a message. And a lot of these should literally never fail, as much as I would like to see the struct causing type alignment does not fit in `usize`
🙂
f852406
to
0985e3a
Compare
0985e3a
to
ed9f18f
Compare
ed9f18f
to
f72b6f9
Compare
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.
Couple notes about a redundant pattern, but this looks a lot better to me than the previous rev. Emilio needs to double check the logic refactoring.
95923f9
to
249b36d
Compare
☔ The latest upstream changes (presumably 2013b8c) made this pull request unmergeable. Please resolve the merge conflicts. |
Use
TryInto
instead ofas
casts.