Skip to content

Commit 887e843

Browse files
committed
Update async-fn-nonsend.rs
The previous commit made the non_sync_with_method_call case pass due to the await being unreachable. Unfortunately, this isn't actually the behavior the test was verifying. This change lifts the panic into a helper function so that the generator analysis still thinks the await is reachable, and therefore we preserve the same testing behavior.
1 parent 787f4cb commit 887e843

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/test/ui/async-await/async-fn-nonsend.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,26 @@ async fn non_send_temporary_in_match() {
3535
}
3636
}
3737

38+
fn get_formatter() -> std::fmt::Formatter<'static> {
39+
panic!()
40+
}
41+
3842
async fn non_sync_with_method_call() {
43+
let f: &mut std::fmt::Formatter = &mut get_formatter();
44+
// It would by nice for this to work.
45+
if non_sync().fmt(f).unwrap() == () {
46+
fut().await;
47+
}
48+
}
49+
50+
async fn non_sync_with_method_call_panic() {
3951
let f: &mut std::fmt::Formatter = panic!();
4052
if non_sync().fmt(f).unwrap() == () {
4153
fut().await;
4254
}
4355
}
4456

45-
async fn non_sync_with_infinite_loop() {
57+
async fn non_sync_with_method_call_infinite_loop() {
4658
let f: &mut std::fmt::Formatter = loop {};
4759
if non_sync().fmt(f).unwrap() == () {
4860
fut().await;
@@ -56,5 +68,7 @@ pub fn pass_assert() {
5668
assert_send(non_send_temporary_in_match());
5769
//~^ ERROR future cannot be sent between threads safely
5870
assert_send(non_sync_with_method_call());
59-
assert_send(non_sync_with_infinite_loop());
71+
//~^ ERROR future cannot be sent between threads safely
72+
assert_send(non_sync_with_method_call_panic());
73+
assert_send(non_sync_with_method_call_infinite_loop());
6074
}

src/test/ui/async-await/async-fn-nonsend.stderr

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: future cannot be sent between threads safely
2-
--> $DIR/async-fn-nonsend.rs:56:17
2+
--> $DIR/async-fn-nonsend.rs:68:17
33
|
44
LL | assert_send(non_send_temporary_in_match());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `non_send_temporary_in_match` is not `Send`
@@ -16,10 +16,34 @@ LL | Some(_) => fut().await,
1616
LL | }
1717
| - `Some(non_send())` is later dropped here
1818
note: required by a bound in `assert_send`
19-
--> $DIR/async-fn-nonsend.rs:52:24
19+
--> $DIR/async-fn-nonsend.rs:64:24
2020
|
2121
LL | fn assert_send(_: impl Send) {}
2222
| ^^^^ required by this bound in `assert_send`
2323

24-
error: aborting due to previous error
24+
error: future cannot be sent between threads safely
25+
--> $DIR/async-fn-nonsend.rs:70:17
26+
|
27+
LL | assert_send(non_sync_with_method_call());
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
29+
|
30+
= help: the trait `Send` is not implemented for `dyn std::fmt::Write`
31+
note: future is not `Send` as this value is used across an await
32+
--> $DIR/async-fn-nonsend.rs:46:14
33+
|
34+
LL | let f: &mut std::fmt::Formatter = &mut get_formatter();
35+
| --------------- has type `Formatter<'_>` which is not `Send`
36+
...
37+
LL | fut().await;
38+
| ^^^^^^ await occurs here, with `get_formatter()` maybe used later
39+
LL | }
40+
LL | }
41+
| - `get_formatter()` is later dropped here
42+
note: required by a bound in `assert_send`
43+
--> $DIR/async-fn-nonsend.rs:64:24
44+
|
45+
LL | fn assert_send(_: impl Send) {}
46+
| ^^^^ required by this bound in `assert_send`
47+
48+
error: aborting due to 2 previous errors
2549

0 commit comments

Comments
 (0)