Skip to content

Rollup of 6 pull requests #96203

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

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1be1157
Remove `--extern-location` and all associated code
jsgf Apr 15, 2022
8cec88b
`alloc`: make `vec!` unavailable under `no_global_oom_handling`
ojeda Apr 15, 2022
ebe3c56
Provide a better diagnostic on failure to meet send bound on futures …
oribenshir Mar 5, 2022
07ee031
Stop using CRATE_DEF_INDEX.
cjgillot Apr 15, 2022
703a336
Define a dedicated error type for `HandleOrNull` and `HandleOrInvalid`.
sunfishcode Mar 27, 2022
5b3023c
Fix an incorrect word in a comment.
sunfishcode Mar 27, 2022
67994b7
Move the `Error` impl for `NotHandle` out of platform-independent code.
sunfishcode Mar 27, 2022
f934043
Split `NotHandle` into `NullHandleError` and `InvalidHandleError`.
sunfishcode Mar 28, 2022
890125d
Add a comment explaining the `(())` idiom for empty structs.
sunfishcode Apr 13, 2022
b7ff103
Update the expected stderr for coerce-issue-49593-box-never.
sunfishcode Apr 15, 2022
19ef182
Update the expected stderr for coerce-issue-49593-box-never.
sunfishcode Apr 19, 2022
0255398
Improve AddrParseError description
chris-morgan Apr 19, 2022
15cb9eb
Rollup merge of #94493 - oribenshir:feature/ISSUE-78543_async_fn_in_f…
Dylan-DPC Apr 19, 2022
3b95471
Rollup merge of #96086 - jsgf:remove-extern-location, r=davidtwco
Dylan-DPC Apr 19, 2022
765ccbf
Rollup merge of #96089 - ojeda:no-vec-no_global_oom_handling, r=Mark-…
Dylan-DPC Apr 19, 2022
a4b7079
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Dylan-DPC Apr 19, 2022
1a4461b
Rollup merge of #96168 - chris-morgan:AddrParseError-description-impr…
Dylan-DPC Apr 19, 2022
3fbc4e2
Rollup merge of #96195 - sunfishcode:sunfishcode/handle-or-error-type…
Dylan-DPC Apr 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Define a dedicated error type for HandleOrNull and HandleOrInvalid.
Define a `NotHandle` type, that implements `std::error::Error`, and use
it as the error type in `HandleOrNull` and `HandleOrInvalid`.
  • Loading branch information
sunfishcode committed Apr 18, 2022
commit 703a33673de30572960eb3fe2c36a0f51083d226
26 changes: 20 additions & 6 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ impl BorrowedHandle<'_> {
}

impl TryFrom<HandleOrNull> for OwnedHandle {
type Error = ();
type Error = NotHandle;

#[inline]
fn try_from(handle_or_null: HandleOrNull) -> Result<Self, ()> {
fn try_from(handle_or_null: HandleOrNull) -> Result<Self, NotHandle> {
let owned_handle = handle_or_null.0;
if owned_handle.handle.is_null() {
// Don't call `CloseHandle`; it'd be harmless, except that it could
// overwrite the `GetLastError` error.
forget(owned_handle);

Err(())
Err(NotHandle(()))
} else {
Ok(owned_handle)
}
Expand Down Expand Up @@ -201,23 +201,37 @@ impl OwnedHandle {
}

impl TryFrom<HandleOrInvalid> for OwnedHandle {
type Error = ();
type Error = NotHandle;

#[inline]
fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, ()> {
fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, NotHandle> {
let owned_handle = handle_or_invalid.0;
if owned_handle.handle == c::INVALID_HANDLE_VALUE {
// Don't call `CloseHandle`; it'd be harmless, except that it could
// overwrite the `GetLastError` error.
forget(owned_handle);

Err(())
Err(NotHandle(()))
} else {
Ok(owned_handle)
}
}
}

/// This is the error type used by [`HandleOrInvalid`] and
/// [`HandleOrNull`] when attempting to convert into a handle,
/// to indicate that the value is not a handle.
#[unstable(feature = "io_safety", issue = "87074")]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct NotHandle(());

#[unstable(feature = "io_safety", issue = "87074")]
impl fmt::Display for NotHandle {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"the return value of a Windows API call indicated an error".fmt(fmt)
}
}

impl AsRawHandle for BorrowedHandle<'_> {
#[inline]
fn as_raw_handle(&self) -> RawHandle {
Expand Down