Skip to content

Commit a99c5e1

Browse files
Rollup merge of #163832 - amirHdev:reject-non-async-coroutine-closures, r=oli-obk
reject non-async coroutine closures as async callables fixes rust-lang/trait-system-refactor-initiative#302 reject non-async coroutine closures in async callable extraction
2 parents 1a63b39 + 23f86c5 commit a99c5e1

11 files changed

Lines changed: 119 additions & 36 deletions

‎compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
440440
) -> Result<(ty::Binder<I, AsyncCallableRelevantTypes<I>>, Vec<I::Predicate>), NoSolution> {
441441
match self_ty.kind() {
442442
ty::CoroutineClosure(def_id, args) => {
443+
if !cx.coroutine_is_async(cx.coroutine_for_closure(def_id)) {
444+
return Err(NoSolution);
445+
}
446+
443447
let args = args.as_coroutine_closure();
444448
let kind_ty = args.kind_ty();
445449
let sig = args.coroutine_closure_sig().skip_binder();

‎tests/ui/iterators/generator_capture_2.current.stderr‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0382]: use of moved value: `f`
2-
--> $DIR/generator_capture_2.rs:27:17
2+
--> $DIR/generator_capture_2.rs:26:17
33
|
44
LL | let f = {
5-
| - move occurs because `f` has type `{gen closure@$DIR/generator_capture_2.rs:16:17: 16:24}`, which does not implement the `Copy` trait
5+
| - move occurs because `f` has type `{gen closure@$DIR/generator_capture_2.rs:15:17: 15:24}`, which does not implement the `Copy` trait
66
...
77
LL | let mut i = f();
88
| --- `f` moved due to this call
@@ -11,7 +11,7 @@ LL | let mut i = f();
1111
| ^ value used here after move
1212
|
1313
note: this value implements `FnOnce`, which causes it to be moved when called
14-
--> $DIR/generator_capture_2.rs:22:17
14+
--> $DIR/generator_capture_2.rs:21:17
1515
|
1616
LL | let mut i = f();
1717
| ^
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0382]: use of moved value: `f`
2+
--> $DIR/generator_capture_2.rs:26:17
3+
|
4+
LL | let f = {
5+
| - move occurs because `f` has type `{gen closure@$DIR/generator_capture_2.rs:15:17: 15:24}`, which does not implement the `Copy` trait
6+
...
7+
LL | let mut i = f();
8+
| --- `f` moved due to this call
9+
...
10+
LL | let mut i = f();
11+
| ^ value used here after move
12+
|
13+
note: this value implements `FnOnce`, which causes it to be moved when called
14+
--> $DIR/generator_capture_2.rs:21:17
15+
|
16+
LL | let mut i = f();
17+
| ^
18+
help: consider cloning the value if the performance cost is acceptable
19+
|
20+
LL | let mut i = f.clone()();
21+
| ++++++++
22+
23+
error: aborting due to 1 previous error
24+
25+
For more information about this error, try `rustc --explain E0382`.

‎tests/ui/iterators/generator_capture_2.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//@ revisions: current next
22
//@ ignore-compare-mode-next-solver (explicit revisions)
33
//@[next] compile-flags: -Znext-solver
4-
//@[next] known-bug: trait-system-refactor-initiative#302
5-
//@[next] check-pass
4+
//@check-fail
65

76
// This test exercises lending behavior for iterator closures which is not yet supported.
87

@@ -24,7 +23,7 @@ fn main() {
2423
assert_eq!(i.next(), Some('o'));
2524
assert_eq!(i.next(), Some('o'));
2625
assert_eq!(i.next(), None);
27-
let mut i = f(); //[current]~ ERROR use of moved value: `f`
26+
let mut i = f(); //~ ERROR use of moved value: `f`
2827
assert_eq!(i.next(), Some('f'));
2928
assert_eq!(i.next(), Some('o'));
3029
assert_eq!(i.next(), Some('o'));

‎tests/ui/iterators/iter-macro-not-async-closure-simplified.narrow.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied
2-
--> $DIR/iter-macro-not-async-closure-simplified.rs:31:21
1+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
2+
--> $DIR/iter-macro-not-async-closure-simplified.rs:30:21
33
|
44
LL | call_async_once(f);
55
| --------------- ^ unsatisfied trait bound
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}`
9+
= help: the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}`
1010
note: required by a bound in `call_async_once`
11-
--> $DIR/iter-macro-not-async-closure-simplified.rs:22:28
11+
--> $DIR/iter-macro-not-async-closure-simplified.rs:21:28
1212
|
1313
LL | ...pl AsyncFnOnce()) {}
1414
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
2+
--> $DIR/iter-macro-not-async-closure-simplified.rs:30:21
3+
|
4+
LL | call_async_once(f);
5+
| --------------- ^ unsatisfied trait bound
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}`
10+
note: required by a bound in `call_async_once`
11+
--> $DIR/iter-macro-not-async-closure-simplified.rs:21:28
12+
|
13+
LL | fn call_async_once(_: impl AsyncFnOnce()) {}
14+
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/iterators/iter-macro-not-async-closure-simplified.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//@[narrow] compile-flags: --diagnostic-width=20
1313
//@[wide] compile-flags: --diagnostic-width=300
1414
//@[next] compile-flags: -Znext-solver
15-
//@[next] known-bug: trait-system-refactor-initiative#302
16-
//@[next] check-pass
15+
//@check-fail
1716

1817
#![feature(yield_expr, iter_macro)]
1918

@@ -29,5 +28,5 @@ fn main() {
2928
}};
3029

3130
call_async_once(f);
32-
//[narrow,wide]~^ ERROR AsyncFnOnce()` is not satisfied
31+
//~^ ERROR AsyncFnOnce()` is not satisfied
3332
}

‎tests/ui/iterators/iter-macro-not-async-closure-simplified.wide.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied
2-
--> $DIR/iter-macro-not-async-closure-simplified.rs:31:21
1+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
2+
--> $DIR/iter-macro-not-async-closure-simplified.rs:30:21
33
|
44
LL | call_async_once(f);
5-
| --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}`
5+
| --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}`
66
| |
77
| required by a bound introduced by this call
88
|
99
note: required by a bound in `call_async_once`
10-
--> $DIR/iter-macro-not-async-closure-simplified.rs:22:28
10+
--> $DIR/iter-macro-not-async-closure-simplified.rs:21:28
1111
|
1212
LL | fn call_async_once(_: impl AsyncFnOnce()) {}
1313
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`

‎tests/ui/iterators/iter-macro-not-async-closure.current.stderr‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied
2-
--> $DIR/iter-macro-not-async-closure.rs:31:34
1+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
2+
--> $DIR/iter-macro-not-async-closure.rs:30:34
33
|
44
LL | let x = pin!(call_async_once(f));
5-
| --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}`
5+
| --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}`
66
| |
77
| required by a bound introduced by this call
88
|
99
note: required by a bound in `call_async_once`
10-
--> $DIR/iter-macro-not-async-closure.rs:20:34
10+
--> $DIR/iter-macro-not-async-closure.rs:19:34
1111
|
1212
LL | async fn call_async_once(f: impl AsyncFnOnce()) {
1313
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
1414

15-
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied
16-
--> $DIR/iter-macro-not-async-closure.rs:31:13
15+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
16+
--> $DIR/iter-macro-not-async-closure.rs:30:13
1717
|
1818
LL | let x = pin!(call_async_once(f));
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}`
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}`
2020
|
2121
note: required by a bound in `call_async_once`
22-
--> $DIR/iter-macro-not-async-closure.rs:20:34
22+
--> $DIR/iter-macro-not-async-closure.rs:19:34
2323
|
2424
LL | async fn call_async_once(f: impl AsyncFnOnce()) {
2525
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
2626

27-
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied
28-
--> $DIR/iter-macro-not-async-closure.rs:34:5
27+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
28+
--> $DIR/iter-macro-not-async-closure.rs:32:5
2929
|
3030
LL | x.poll(&mut Context::from_waker(Waker::noop()));
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}`
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}`
3232
|
3333
note: required by a bound in `call_async_once`
34-
--> $DIR/iter-macro-not-async-closure.rs:20:34
34+
--> $DIR/iter-macro-not-async-closure.rs:19:34
3535
|
3636
LL | async fn call_async_once(f: impl AsyncFnOnce()) {
3737
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
2+
--> $DIR/iter-macro-not-async-closure.rs:30:34
3+
|
4+
LL | let x = pin!(call_async_once(f));
5+
| --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `call_async_once`
10+
--> $DIR/iter-macro-not-async-closure.rs:19:34
11+
|
12+
LL | async fn call_async_once(f: impl AsyncFnOnce()) {
13+
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
14+
15+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
16+
--> $DIR/iter-macro-not-async-closure.rs:30:13
17+
|
18+
LL | let x = pin!(call_async_once(f));
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}`
20+
|
21+
note: required by a bound in `call_async_once`
22+
--> $DIR/iter-macro-not-async-closure.rs:19:34
23+
|
24+
LL | async fn call_async_once(f: impl AsyncFnOnce()) {
25+
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
26+
27+
error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied
28+
--> $DIR/iter-macro-not-async-closure.rs:32:5
29+
|
30+
LL | x.poll(&mut Context::from_waker(Waker::noop()));
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}`
32+
|
33+
note: required by a bound in `call_async_once`
34+
--> $DIR/iter-macro-not-async-closure.rs:19:34
35+
|
36+
LL | async fn call_async_once(f: impl AsyncFnOnce()) {
37+
| ^^^^^^^^^^^^^ required by this bound in `call_async_once`
38+
39+
error: aborting due to 3 previous errors
40+
41+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)