-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #96195 - sunfishcode:sunfishcode/handle-or-error-type, …
…r=joshtriplett Define a dedicated error type for `HandleOrNull` and `HandleOrInvalid`. Define `NullHandleError` and `InvalidHandleError` types, that implement std::error::Error, and use them as the error types in `HandleOrNull` and `HandleOrInvalid`, This addresses [this concern](#87074 (comment)). This is the same as #95387. r? `@joshtriplett`
- Loading branch information
Showing
5 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/ui/coercion/coerce-issue-49593-box-never-windows.nofallback.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0277]: the trait bound `(): std::error::Error` is not satisfied | ||
--> $DIR/coerce-issue-49593-box-never-windows.rs:18:53 | ||
| | ||
LL | /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | ||
| | ||
= help: the following other types implement trait `std::error::Error`: | ||
! | ||
&'a T | ||
AccessError | ||
AddrParseError | ||
Arc<T> | ||
BorrowError | ||
BorrowMutError | ||
Box<T> | ||
and 45 others | ||
= note: required for the cast to the object type `dyn std::error::Error` | ||
|
||
error[E0277]: the trait bound `(): std::error::Error` is not satisfied | ||
--> $DIR/coerce-issue-49593-box-never-windows.rs:23:49 | ||
| | ||
LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | ||
| | ||
= help: the following other types implement trait `std::error::Error`: | ||
! | ||
&'a T | ||
AccessError | ||
AddrParseError | ||
Arc<T> | ||
BorrowError | ||
BorrowMutError | ||
Box<T> | ||
and 45 others | ||
= note: required for the cast to the object type `(dyn std::error::Error + 'static)` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
58 changes: 58 additions & 0 deletions
58
src/test/ui/coercion/coerce-issue-49593-box-never-windows.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// revisions: nofallback fallback | ||
// only-windows - the number of `Error` impls is platform-dependent | ||
//[fallback] check-pass | ||
//[nofallback] check-fail | ||
|
||
#![feature(never_type)] | ||
#![cfg_attr(fallback, feature(never_type_fallback))] | ||
#![allow(unreachable_code)] | ||
|
||
use std::error::Error; | ||
use std::mem; | ||
|
||
fn raw_ptr_box<T>(t: T) -> *mut T { | ||
panic!() | ||
} | ||
|
||
fn foo(x: !) -> Box<dyn Error> { | ||
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x) | ||
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied | ||
} | ||
|
||
fn foo_raw_ptr(x: !) -> *mut dyn Error { | ||
/* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) | ||
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied | ||
} | ||
|
||
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error { | ||
/* an unsize coercion won't compile here, and it is indeed not used | ||
because there is nothing requiring the _ to be Sized */ | ||
d as *mut _ | ||
} | ||
|
||
trait Xyz {} | ||
struct S; | ||
struct T; | ||
impl Xyz for S {} | ||
impl Xyz for T {} | ||
|
||
fn foo_no_never() { | ||
let mut x /* : Option<S> */ = None; | ||
let mut first_iter = false; | ||
loop { | ||
if !first_iter { | ||
let y: Box<dyn Xyz> | ||
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap()); | ||
} | ||
|
||
x = Some(S); | ||
first_iter = true; | ||
} | ||
|
||
let mut y : Option<S> = None; | ||
// assert types are equal | ||
mem::swap(&mut x, &mut y); | ||
} | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters