-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #104594 - compiler-errors:dyn-star-rcvr, r=eholk,este…
…bank Properly handle `Pin<&mut dyn* Trait>` receiver in codegen This ensures we can actually await a `dyn* Future`, which seems important for async fn in dyn trait. Also, disable `dyn*` trait upcasting. It's not exactly complete right now, and can cause strange ICEs for no reason -- nobody's using it either. I thought it was cute to implement when I did it, but I didn't think about how it interacts structurally with `CoerceUnsized` correctly. Fixes #104794, presumably removing `dyn*` upcasting and its `CoerceUnsized` issues does the trick.
- Loading branch information
Showing
14 changed files
with
179 additions
and
43 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// run-pass | ||
// edition:2021 | ||
// check-run-results | ||
|
||
#![feature(dyn_star)] | ||
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
|
||
use std::future::Future; | ||
|
||
async fn foo(f: dyn* Future<Output = i32>) { | ||
println!("value: {}", f.await); | ||
} | ||
|
||
async fn async_main() { | ||
foo(Box::pin(async { 1 })).await | ||
} | ||
|
||
// ------------------------------------------------------------------------- // | ||
// Implementation Details Below... | ||
|
||
use std::pin::Pin; | ||
use std::task::*; | ||
|
||
pub fn noop_waker() -> Waker { | ||
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE); | ||
|
||
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld | ||
unsafe { Waker::from_raw(raw) } | ||
} | ||
|
||
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop); | ||
|
||
unsafe fn noop_clone(_p: *const ()) -> RawWaker { | ||
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE) | ||
} | ||
|
||
unsafe fn noop(_p: *const ()) {} | ||
|
||
fn main() { | ||
let mut fut = async_main(); | ||
|
||
// Poll loop, just to test the future... | ||
let waker = noop_waker(); | ||
let ctx = &mut Context::from_waker(&waker); | ||
|
||
loop { | ||
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } { | ||
Poll::Pending => {} | ||
Poll::Ready(()) => break, | ||
} | ||
} | ||
} |
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 @@ | ||
value: 1 |
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,11 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/dispatch-on-pin-mut.rs:5:12 | ||
| | ||
LL | #![feature(dyn_star)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
43 | ||
44 |
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,11 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/dont-unsize-coerce-dyn-star.rs:4:12 | ||
| | ||
LL | #![feature(dyn_star)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
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,13 @@ | ||
#![feature(dyn_star, trait_upcasting)] | ||
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
|
||
trait A: B {} | ||
trait B {} | ||
impl A for usize {} | ||
impl B for usize {} | ||
|
||
fn main() { | ||
let x: Box<dyn* A> = Box::new(1usize as dyn* A); | ||
let y: Box<dyn* B> = x; | ||
//~^ ERROR mismatched types | ||
} |
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,23 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/no-unsize-coerce-dyn-trait.rs:1:12 | ||
| | ||
LL | #![feature(dyn_star, trait_upcasting)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/no-unsize-coerce-dyn-trait.rs:11:26 | ||
| | ||
LL | let y: Box<dyn* B> = x; | ||
| ----------- ^ expected trait `B`, found trait `A` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected struct `Box<dyn* B>` | ||
found struct `Box<dyn* A>` | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/upcast.rs:3:12 | ||
| | ||
LL | #![feature(dyn_star, trait_upcasting)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: `dyn* Foo` needs to be a pointer-sized type | ||
--> $DIR/upcast.rs:30:23 | ||
| | ||
LL | let w: dyn* Bar = w; | ||
| ^ `dyn* Foo` needs to be a pointer-sized type | ||
| | ||
= help: the trait `PointerSized` is not implemented for `dyn* Foo` | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |