Skip to content

Commit 3cd8a0b

Browse files
Rollup merge of rust-lang#152327 - adwinwhite:fix-non-defining-use-ices-ready, r=lcnr
Check stalled coroutine obligations eagerly Fixes rust-lang#151322 Fixes rust-lang#151323 Fixes rust-lang#137916 Fixes rust-lang#138274 The problem is that stalled coroutine obligations can't be satisifed so that they cause normalization to fail in `mir_borrowck`. Thus, we failed to register any opaque to storage in the next solver. I fix it by checking these obligations earlier in `mir_borrowck`. r? @lcnr
2 parents 548228b + f248395 commit 3cd8a0b

File tree

14 files changed

+202
-140
lines changed

14 files changed

+202
-140
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ fn mir_borrowck(
121121
let (input_body, _) = tcx.mir_promoted(def);
122122
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
123123

124+
// We should eagerly check stalled coroutine obligations from HIR typeck.
125+
// Not doing so leads to silent normalization failures later, which will
126+
// fail to register opaque types in the next solver.
127+
tcx.check_coroutine_obligations(def)?;
128+
124129
let input_body: &Body<'_> = &input_body.borrow();
125130
if let Some(guar) = input_body.tainted_by_errors {
126131
debug!("Skipping borrowck because of tainted body");

compiler/rustc_interface/src/passes.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,18 +1116,14 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
11161116
{
11171117
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
11181118
}
1119-
if tcx.is_coroutine(def_id.to_def_id()) {
1120-
tcx.ensure_ok().mir_coroutine_witnesses(def_id);
1121-
let _ = tcx.ensure_ok().check_coroutine_obligations(
1122-
tcx.typeck_root_def_id(def_id.to_def_id()).expect_local(),
1119+
if tcx.is_coroutine(def_id.to_def_id())
1120+
&& (!tcx.is_async_drop_in_place_coroutine(def_id.to_def_id()))
1121+
{
1122+
// Eagerly check the unsubstituted layout for cycles.
1123+
tcx.ensure_ok().layout_of(
1124+
ty::TypingEnv::post_analysis(tcx, def_id.to_def_id())
1125+
.as_query_input(tcx.type_of(def_id).instantiate_identity()),
11231126
);
1124-
if !tcx.is_async_drop_in_place_coroutine(def_id.to_def_id()) {
1125-
// Eagerly check the unsubstituted layout for cycles.
1126-
tcx.ensure_ok().layout_of(
1127-
ty::TypingEnv::post_analysis(tcx, def_id.to_def_id())
1128-
.as_query_input(tcx.type_of(def_id).instantiate_identity()),
1129-
);
1130-
}
11311127
}
11321128
});
11331129
});

tests/crashes/137916.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/crashes/138274.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ui/async-await/issue-70818.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
use std::future::Future;
44
fn foo<T: Send, U>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
5-
//~^ ERROR future cannot be sent between threads safely
5+
//~^ ERROR: future cannot be sent between threads safely
66
async { (ty, ty1) }
7-
//~^ ERROR future cannot be sent between threads safely
87
}
98

109
fn main() {}
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
error: future cannot be sent between threads safely
2-
--> $DIR/issue-70818.rs:6:5
3-
|
4-
LL | async { (ty, ty1) }
5-
| ^^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
6-
|
7-
note: captured value is not `Send`
8-
--> $DIR/issue-70818.rs:6:18
9-
|
10-
LL | async { (ty, ty1) }
11-
| ^^^ has type `U` which is not `Send`
12-
note: required by a bound in an opaque type
13-
--> $DIR/issue-70818.rs:4:69
14-
|
15-
LL | fn foo<T: Send, U>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
16-
| ^^^^
17-
help: consider restricting type parameter `U` with trait `Send`
18-
|
19-
LL | fn foo<T: Send, U: std::marker::Send>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
20-
| +++++++++++++++++++
21-
221
error: future cannot be sent between threads safely
232
--> $DIR/issue-70818.rs:4:38
243
|
@@ -35,5 +14,5 @@ help: consider restricting type parameter `U` with trait `Send`
3514
LL | fn foo<T: Send, U: std::marker::Send>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
3615
| +++++++++++++++++++
3716

38-
error: aborting due to 2 previous errors
17+
error: aborting due to 1 previous error
3918

tests/ui/async-await/issue-70935-complex-spans.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
1515
fn foo(x: NotSync) -> impl Future + Send {
1616
//~^ ERROR `*mut ()` cannot be shared between threads safely
1717
async move {
18-
//~^ ERROR `*mut ()` cannot be shared between threads safely
1918
baz(|| async {
2019
foo(x.clone());
2120
}).await;
Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,3 @@
1-
error[E0277]: `*mut ()` cannot be shared between threads safely
2-
--> $DIR/issue-70935-complex-spans.rs:17:5
3-
|
4-
LL | / async move {
5-
LL | |
6-
LL | | baz(|| async {
7-
LL | | foo(x.clone());
8-
LL | | }).await;
9-
LL | | }
10-
| |_____^ `*mut ()` cannot be shared between threads safely
11-
|
12-
= help: within `NotSync`, the trait `Sync` is not implemented for `*mut ()`
13-
note: required because it appears within the type `PhantomData<*mut ()>`
14-
--> $SRC_DIR/core/src/marker.rs:LL:COL
15-
note: required because it appears within the type `NotSync`
16-
--> $DIR/issue-70935-complex-spans.rs:9:8
17-
|
18-
LL | struct NotSync(PhantomData<*mut ()>);
19-
| ^^^^^^^
20-
= note: required for `&NotSync` to implement `Send`
21-
note: required because it's used within this closure
22-
--> $DIR/issue-70935-complex-spans.rs:19:13
23-
|
24-
LL | baz(|| async {
25-
| ^^
26-
note: required because it's used within this `async` fn body
27-
--> $DIR/issue-70935-complex-spans.rs:12:67
28-
|
29-
LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
30-
| ___________________________________________________________________^
31-
LL | | }
32-
| |_^
33-
note: required because it's used within this `async` block
34-
--> $DIR/issue-70935-complex-spans.rs:17:5
35-
|
36-
LL | async move {
37-
| ^^^^^^^^^^
38-
note: required by a bound in an opaque type
39-
--> $DIR/issue-70935-complex-spans.rs:15:37
40-
|
41-
LL | fn foo(x: NotSync) -> impl Future + Send {
42-
| ^^^^
43-
441
error[E0277]: `*mut ()` cannot be shared between threads safely
452
--> $DIR/issue-70935-complex-spans.rs:15:23
463
|
@@ -57,7 +14,7 @@ LL | struct NotSync(PhantomData<*mut ()>);
5714
| ^^^^^^^
5815
= note: required for `&NotSync` to implement `Send`
5916
note: required because it's used within this closure
60-
--> $DIR/issue-70935-complex-spans.rs:19:13
17+
--> $DIR/issue-70935-complex-spans.rs:18:13
6118
|
6219
LL | baz(|| async {
6320
| ^^
@@ -74,6 +31,6 @@ note: required because it's used within this `async` block
7431
LL | async move {
7532
| ^^^^^^^^^^
7633

77-
error: aborting due to 2 previous errors
34+
error: aborting due to 1 previous error
7835

7936
For more information about this error, try `rustc --explain E0277`.

tests/ui/coroutine/issue-105084.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ fn main() {
3636
// one inside `g` and one inside `h`.
3737
// Proceed and drop `t` in `g`.
3838
Pin::new(&mut g).resume(());
39-
//~^ ERROR borrow of moved value: `g`
4039

4140
// Proceed and drop `t` in `h` -> double free!
4241
Pin::new(&mut h).resume(());
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
error[E0382]: borrow of moved value: `g`
2-
--> $DIR/issue-105084.rs:38:14
3-
|
4-
LL | let mut g = #[coroutine]
5-
| ----- move occurs because `g` has type `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}`, which does not implement the `Copy` trait
6-
...
7-
LL | let mut h = copy(g);
8-
| - value moved here
9-
...
10-
LL | Pin::new(&mut g).resume(());
11-
| ^^^^^^ value borrowed here after move
12-
|
13-
note: consider changing this parameter type in function `copy` to borrow instead if owning the value isn't necessary
14-
--> $DIR/issue-105084.rs:10:21
15-
|
16-
LL | fn copy<T: Copy>(x: T) -> T {
17-
| ---- ^ this parameter takes ownership of the value
18-
| |
19-
| in this function
20-
help: consider cloning the value if the performance cost is acceptable
21-
|
22-
LL | let mut h = copy(g.clone());
23-
| ++++++++
24-
251
error[E0277]: the trait bound `Box<(i32, ())>: Copy` is not satisfied in `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}`
262
--> $DIR/issue-105084.rs:32:17
273
|
@@ -45,7 +21,6 @@ note: required by a bound in `copy`
4521
LL | fn copy<T: Copy>(x: T) -> T {
4622
| ^^^^ required by this bound in `copy`
4723

48-
error: aborting due to 2 previous errors
24+
error: aborting due to 1 previous error
4925

50-
Some errors have detailed explanations: E0277, E0382.
51-
For more information about an error, try `rustc --explain E0277`.
26+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)