-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Broken Mir Resulting From Async Function Pointer Cast #98604
Comments
This ICE is also triggered by unsizing coercion such as follows: type AsyncFnPtr = Box<
dyn Fn() -> std::pin::Pin<Box<dyn std::future::Future<Output = ()>>>,
>;
async fn test() {}
fn main() {
let _: AsyncFnPtr = Box::new(test);
} |
Borrowck is correct in rejecting this code, since the cast is not allowed like this. Looks like some earlier pass didn't check it it correctly. |
Yea regular typeck should already reject that cast/coercion |
Strangely, inlining the type alias's definition gives us:
|
I investigated this closer and.. found a soundness bug! #98608 |
Seems like the soundness bug is caused by the same issue, so fixing that should fix this as well. It's just that here borrowck managed to find the broken code and bail out, but there, no one was there to catch it. |
Correct error in 1.60.0, and nightly prior to f132bcf: error[E0271]: type mismatch resolving `<fn() -> impl Future<Output = ()> {test} as FnOnce<()>>::Output == Pin<Box<(dyn Future<Output = ()> + 'static)>>`
--> src/main.rs:9:5
|
9 | Box::new(test) as AsyncFnPtr;
| ^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
|
note: while checking the return type of the `async fn`
--> src/main.rs:5:17
|
5 | async fn test() {}
| ^ checked the `Output` of this `async fn`, found opaque type
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
found opaque type `impl Future<Output = ()>`
= note: required for the cast to the object type `dyn Fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>>`
For more information about this error, try `rustc --explain E0271`. |
just for the record, oli figured out the bug, so other ppl don't waste too much time investigating |
Marked p-medium as per zulip triage discussion |
Link for WG-prioritization Zulip discussion |
Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: