-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Check stalled coroutine obligations eagerly #152327
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One less duplicate error. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,6 @@ fn main() { | |
| // one inside `g` and one inside `h`. | ||
| // Proceed and drop `t` in `g`. | ||
| Pin::new(&mut g).resume(()); | ||
| //~^ ERROR borrow of moved value: `g` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we check stalled_coroutine_obligations before actual borrowck, we won't have borrowck diagnostics if those obligations fail. |
||
|
|
||
| // Proceed and drop `t` in `h` -> double free! | ||
| Pin::new(&mut h).resume(()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //@ edition: 2021 | ||
|
|
||
| // Regression tests for #137916 and #138274 | ||
| // We now check stalled coroutine obligations eagerly at the start of `mir_borrowck`. | ||
| // So these unsatisfied bounds are caught before causing ICEs. | ||
| use std::ptr::null; | ||
|
|
||
| async fn a() -> Box<dyn Send> { | ||
| Box::new(async { | ||
| //~^ ERROR: future cannot be sent between threads safely | ||
| let non_send = null::<()>(); | ||
| &non_send; | ||
| async {}.await | ||
| }) | ||
| } | ||
|
|
||
|
|
||
| trait Trait {} | ||
| fn foo() -> Box<dyn Trait> { todo!() } | ||
|
|
||
| fn fetch() { | ||
| async { | ||
| let fut = async { | ||
| let _x = foo(); | ||
| async {}.await; | ||
| }; | ||
| let _: Box<dyn Send> = Box::new(fut); | ||
| //~^ ERROR: future cannot be sent between threads safely | ||
| }; | ||
| } | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| error: future cannot be sent between threads safely | ||
| --> $DIR/stalled-coroutine-obligations.rs:9:5 | ||
| | | ||
| LL | / Box::new(async { | ||
| LL | | | ||
| LL | | let non_send = null::<()>(); | ||
| LL | | &non_send; | ||
| LL | | async {}.await | ||
| LL | | }) | ||
| | |______^ future created by async block is not `Send` | ||
| | | ||
| = help: within `{async block@$DIR/stalled-coroutine-obligations.rs:9:14: 9:19}`, the trait `Send` is not implemented for `*const ()` | ||
| note: future is not `Send` as this value is used across an await | ||
| --> $DIR/stalled-coroutine-obligations.rs:13:18 | ||
| | | ||
| LL | let non_send = null::<()>(); | ||
| | -------- has type `*const ()` which is not `Send` | ||
| LL | &non_send; | ||
| LL | async {}.await | ||
| | ^^^^^ await occurs here, with `non_send` maybe used later | ||
| = note: required for the cast from `Box<{async block@$DIR/stalled-coroutine-obligations.rs:9:14: 9:19}>` to `Box<dyn Send>` | ||
|
|
||
| error: future cannot be sent between threads safely | ||
| --> $DIR/stalled-coroutine-obligations.rs:27:32 | ||
| | | ||
| LL | let _: Box<dyn Send> = Box::new(fut); | ||
| | ^^^^^^^^^^^^^ future created by async block is not `Send` | ||
| | | ||
| = help: the trait `Send` is not implemented for `dyn Trait` | ||
| note: future is not `Send` as this value is used across an await | ||
| --> $DIR/stalled-coroutine-obligations.rs:25:22 | ||
| | | ||
| LL | let _x = foo(); | ||
| | -- has type `Box<dyn Trait>` which is not `Send` | ||
| LL | async {}.await; | ||
| | ^^^^^ await occurs here, with `_x` maybe used later | ||
| = note: required for the cast from `Box<{async block@$DIR/stalled-coroutine-obligations.rs:23:19: 23:24}>` to `Box<dyn Send>` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //@ edition: 2024 | ||
| //@ compile-flags: -Znext-solver --diagnostic-width=300 | ||
|
|
||
| // Previously we check stalled coroutine obligations after borrowck pass. | ||
| // And we wrongly assume that these obligations hold in borrowck which leads to | ||
| // silent normalization failures. | ||
| // In the next solver, we register opaques types via `NormalizesTo` goals. | ||
| // So these failures also cause those opaques types not registered in storage. | ||
| // | ||
| // Regression test for #151322 and #151323. | ||
|
|
||
| #![feature(type_alias_impl_trait)] | ||
| #![feature(negative_impls)] | ||
| #![feature(auto_traits)] | ||
|
|
||
| fn stalled_copy_clone() { | ||
| type T = impl Copy; | ||
| let foo: T = async {}; | ||
| //~^ ERROR: the trait bound | ||
|
|
||
| type U = impl Clone; | ||
| let bar: U = async {}; | ||
| //~^ ERROR: the trait bound | ||
| } | ||
|
|
||
| auto trait Valid {} | ||
| struct False; | ||
| impl !Valid for False {} | ||
|
|
||
| fn stalled_auto_traits() { | ||
| type T = impl Valid; | ||
| let a = False; | ||
| let foo: T = async { a }; | ||
| //~^ ERROR: the trait bound `False: Valid` is not satisfied | ||
| } | ||
|
|
||
|
|
||
| trait Trait { | ||
| fn stalled_send(&self, b: *mut ()) -> impl Future + Send { | ||
| //~^ ERROR: type mismatch resolving | ||
| //~| ERROR: type mismatch resolving | ||
| async move { | ||
| //~^ ERROR: type mismatch resolving | ||
| b | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fn main() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One less duplicate error.