-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove unnecesary "as" casts. #32701
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -191,7 +191,7 @@ pub const ERROR_OPERATION_ABORTED: DWORD = 995; | |||
pub const ERROR_IO_PENDING: DWORD = 997; | |||
pub const ERROR_TIMEOUT: DWORD = 0x5B4; | |||
|
|||
pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE; | |||
pub const INVALID_HANDLE_VALUE: HANDLE = !(0 as HANDLE); |
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.
HANDLE
is a *mut c_void
and you can't apply !
to a pointer.
ee1582a
to
7280e4b
Compare
Passes "make check" on Linux and on Mingw. |
@@ -106,7 +106,7 @@ impl<T> TypedArenaChunk<T> { | |||
unsafe { | |||
if mem::size_of::<T>() == 0 { | |||
// A pointer as large as possible for zero-sized elements. | |||
!0 as *mut T | |||
(!0usize) as *mut T |
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.
How come this was changed? Seems slightly less readable now?
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 don't understand why the original code did the correct thing (but it did/does). !0
on its own is an i32 (value -1). i32 cast to a pointer is valid, yet this seems to infer using usize.
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.
@bluss It appears that !0 as *mut T
has a magical power to fix the type of the integer literal to usize
. It looks more and more suspicious when we see that LLVM inttoptr
is defined as zero extention.
- "0 as *mut _" -> "ptr::null_mut()"; and the same goes for ptr::null() - Simplify "0 as c_int" to "0" when the context already expects c_int - And so on... Signed-off-by: NODA, Kai <[email protected]>
7280e4b
to
ecfacb5
Compare
☔ The latest upstream changes (presumably #32980) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
0 as *mut _
->ptr::null_mut()
; and the same goes forptr::null()
0 as c_int
to0
when the context already expectsc_int