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
Does NTSTATUS
need an Eq
implementation?
#739
Comments
Another question that doesn't feel worthy for a separate issue: where should type changes be requested for thing like https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record turning |
This is controlled by the https://github.com/microsoft/win32metadata/ project that produces the metadata describing these APIs. You can create an issue there with suggestions to improve the metadata. |
Great, it's actually documented how to set up such an override in https://github.com/microsoft/win32metadata#how-you-can-help / https://github.com/microsoft/win32metadata#changing-fieldparameter-types, without touching the underlying header source 👍 (Not sure if these overrides should, or will at some point, be propagated back into Windows headers?) |
Following [1] this improves the type annotation for the `ExceptionCode`, its values mentioned in [2] are of `NTSTATUS` type. When the Rust bindings implement `Eq` for `NTSTATUS` this allows simple `match` blocks without converting between (unsigned) integer types. [1]: microsoft/windows-rs#739 (comment) [2]: https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
I just had a quick look and #[repr(transparent)]
#[derive(:: std :: clone :: Clone, :: std :: marker :: Copy)]
pub struct NTSTATUS(pub i32);
impl NTSTATUS {}
impl ::std::default::Default for NTSTATUS {
fn default() -> Self {
Self(0)
}
}
impl NTSTATUS {
pub const NULL: Self = Self(0);
pub fn is_null(&self) -> bool {
self.0 == 0
}
}
impl ::std::fmt::Debug for NTSTATUS {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.debug_struct("NTSTATUS")
.field("Value", &format_args!("{:?}", self.0))
.finish()
}
}
impl ::std::cmp::PartialEq for NTSTATUS {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::std::cmp::Eq for NTSTATUS {}
unsafe impl ::windows::Abi for NTSTATUS {
type Abi = Self;
} |
Following [1] this improves the type annotation for the `ExceptionCode`, its values mentioned in [2] are of `NTSTATUS` type. When the Rust bindings implement `Eq` for `NTSTATUS` this allows simple `match` blocks without converting between (unsigned) integer types. [1]: microsoft/windows-rs#739 (comment) [2]: https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
@kennykerr Check - I misread and misreported the error. It must be implemented through error: to use a constant of type `NTSTATUS` in a pattern, `NTSTATUS` must be annotated with `#[derive(PartialEq, Eq)]`
--> tests/handles/tests/null.rs:45:9
|
45 | SystemServices::DBG_PRINTEXCEPTION_WIDE_C | SystemServices::DBG_PRINTEXCEPTION_C
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: to use a constant of type `NTSTATUS` in a pattern, `NTSTATUS` must be annotated with `#[derive(PartialEq, Eq)]`
--> tests/handles/tests/null.rs:45:53
|
45 | SystemServices::DBG_PRINTEXCEPTION_WIDE_C | SystemServices::DBG_PRINTEXCEPTION_C
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ See also https://rust-lang.github.io/rfcs/1445-restrict-constants-in-patterns.html. |
We had an issue for this at some point, but I'm failing to find it. We moved away from deriving some of these traits because it really hurt compile times. We might want to look at putting derives back in these specific cases and see how much it hurts compile times nowadays. |
I'll see what I can do - there are many structs that |
@rylev - I ended up going back to deriving as much as possible - its just much simpler - but for structs its quite a mess as there are just so many scenarios that aren't supported by derive. I'll try to get these cleaned up and get this working. |
Did this regress? Version 0.38.0 defines NTSTATUS like so #[repr(transparent)]
pub struct NTSTATUS(pub i32); NTSTATUS derives neither Eq nor PartialEq, so I see this error message
|
No regress,
So, can two |
@toshipiazza see #1869 for a fix. |
#707 (comment)
The text was updated successfully, but these errors were encountered: