diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index c92fdea176670..a7e02f07661c6 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -440,6 +440,10 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable Result<(ty::Binder>, Vec), NoSolution> { match self_ty.kind() { ty::CoroutineClosure(def_id, args) => { + if !cx.coroutine_is_async(cx.coroutine_for_closure(def_id)) { + return Err(NoSolution); + } + let args = args.as_coroutine_closure(); let kind_ty = args.kind_ty(); let sig = args.coroutine_closure_sig().skip_binder(); diff --git a/tests/ui/iterators/generator_capture_2.current.stderr b/tests/ui/iterators/generator_capture_2.current.stderr index f4d0e9ff33240..da3e9288eda26 100644 --- a/tests/ui/iterators/generator_capture_2.current.stderr +++ b/tests/ui/iterators/generator_capture_2.current.stderr @@ -1,8 +1,8 @@ error[E0382]: use of moved value: `f` - --> $DIR/generator_capture_2.rs:27:17 + --> $DIR/generator_capture_2.rs:26:17 | LL | let f = { - | - move occurs because `f` has type `{gen closure@$DIR/generator_capture_2.rs:16:17: 16:24}`, which does not implement the `Copy` trait + | - move occurs because `f` has type `{gen closure@$DIR/generator_capture_2.rs:15:17: 15:24}`, which does not implement the `Copy` trait ... LL | let mut i = f(); | --- `f` moved due to this call @@ -11,7 +11,7 @@ LL | let mut i = f(); | ^ value used here after move | note: this value implements `FnOnce`, which causes it to be moved when called - --> $DIR/generator_capture_2.rs:22:17 + --> $DIR/generator_capture_2.rs:21:17 | LL | let mut i = f(); | ^ diff --git a/tests/ui/iterators/generator_capture_2.next.stderr b/tests/ui/iterators/generator_capture_2.next.stderr new file mode 100644 index 0000000000000..da3e9288eda26 --- /dev/null +++ b/tests/ui/iterators/generator_capture_2.next.stderr @@ -0,0 +1,25 @@ +error[E0382]: use of moved value: `f` + --> $DIR/generator_capture_2.rs:26:17 + | +LL | let f = { + | - move occurs because `f` has type `{gen closure@$DIR/generator_capture_2.rs:15:17: 15:24}`, which does not implement the `Copy` trait +... +LL | let mut i = f(); + | --- `f` moved due to this call +... +LL | let mut i = f(); + | ^ value used here after move + | +note: this value implements `FnOnce`, which causes it to be moved when called + --> $DIR/generator_capture_2.rs:21:17 + | +LL | let mut i = f(); + | ^ +help: consider cloning the value if the performance cost is acceptable + | +LL | let mut i = f.clone()(); + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/iterators/generator_capture_2.rs b/tests/ui/iterators/generator_capture_2.rs index 5277dbb203732..af80475e05419 100644 --- a/tests/ui/iterators/generator_capture_2.rs +++ b/tests/ui/iterators/generator_capture_2.rs @@ -1,8 +1,7 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -//@[next] known-bug: trait-system-refactor-initiative#302 -//@[next] check-pass +//@check-fail // This test exercises lending behavior for iterator closures which is not yet supported. @@ -24,7 +23,7 @@ fn main() { assert_eq!(i.next(), Some('o')); assert_eq!(i.next(), Some('o')); assert_eq!(i.next(), None); - let mut i = f(); //[current]~ ERROR use of moved value: `f` + let mut i = f(); //~ ERROR use of moved value: `f` assert_eq!(i.next(), Some('f')); assert_eq!(i.next(), Some('o')); assert_eq!(i.next(), Some('o')); diff --git a/tests/ui/iterators/iter-macro-not-async-closure-simplified.narrow.stderr b/tests/ui/iterators/iter-macro-not-async-closure-simplified.narrow.stderr index 7aaff4c7bf679..c337681c97346 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure-simplified.narrow.stderr +++ b/tests/ui/iterators/iter-macro-not-async-closure-simplified.narrow.stderr @@ -1,14 +1,14 @@ -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure-simplified.rs:31:21 +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure-simplified.rs:30:21 | LL | call_async_once(f); | --------------- ^ unsatisfied trait bound | | | required by a bound introduced by this call | - = help: the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}` + = help: the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}` note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure-simplified.rs:22:28 + --> $DIR/iter-macro-not-async-closure-simplified.rs:21:28 | LL | ...pl AsyncFnOnce()) {} | ^^^^^^^^^^^^^ required by this bound in `call_async_once` diff --git a/tests/ui/iterators/iter-macro-not-async-closure-simplified.next.stderr b/tests/ui/iterators/iter-macro-not-async-closure-simplified.next.stderr new file mode 100644 index 0000000000000..93086b18009fa --- /dev/null +++ b/tests/ui/iterators/iter-macro-not-async-closure-simplified.next.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure-simplified.rs:30:21 + | +LL | call_async_once(f); + | --------------- ^ unsatisfied trait bound + | | + | required by a bound introduced by this call + | + = help: the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}` +note: required by a bound in `call_async_once` + --> $DIR/iter-macro-not-async-closure-simplified.rs:21:28 + | +LL | fn call_async_once(_: impl AsyncFnOnce()) {} + | ^^^^^^^^^^^^^ required by this bound in `call_async_once` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/iterators/iter-macro-not-async-closure-simplified.rs b/tests/ui/iterators/iter-macro-not-async-closure-simplified.rs index e8c31f0eed879..d0782474f09c2 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure-simplified.rs +++ b/tests/ui/iterators/iter-macro-not-async-closure-simplified.rs @@ -12,8 +12,7 @@ //@[narrow] compile-flags: --diagnostic-width=20 //@[wide] compile-flags: --diagnostic-width=300 //@[next] compile-flags: -Znext-solver -//@[next] known-bug: trait-system-refactor-initiative#302 -//@[next] check-pass +//@check-fail #![feature(yield_expr, iter_macro)] @@ -29,5 +28,5 @@ fn main() { }}; call_async_once(f); - //[narrow,wide]~^ ERROR AsyncFnOnce()` is not satisfied + //~^ ERROR AsyncFnOnce()` is not satisfied } diff --git a/tests/ui/iterators/iter-macro-not-async-closure-simplified.wide.stderr b/tests/ui/iterators/iter-macro-not-async-closure-simplified.wide.stderr index 60a94e070eaba..6a2e8a115f23e 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure-simplified.wide.stderr +++ b/tests/ui/iterators/iter-macro-not-async-closure-simplified.wide.stderr @@ -1,13 +1,13 @@ -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure-simplified.rs:31:21 +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure-simplified.rs:30:21 | LL | call_async_once(f); - | --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:25:21: 25:28}` + | --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure-simplified.rs:24:21: 24:28}` | | | required by a bound introduced by this call | note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure-simplified.rs:22:28 + --> $DIR/iter-macro-not-async-closure-simplified.rs:21:28 | LL | fn call_async_once(_: impl AsyncFnOnce()) {} | ^^^^^^^^^^^^^ required by this bound in `call_async_once` diff --git a/tests/ui/iterators/iter-macro-not-async-closure.current.stderr b/tests/ui/iterators/iter-macro-not-async-closure.current.stderr index ca20bbf4e3150..8e4df855eab56 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure.current.stderr +++ b/tests/ui/iterators/iter-macro-not-async-closure.current.stderr @@ -1,37 +1,37 @@ -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:31:34 +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure.rs:30:34 | LL | let x = pin!(call_async_once(f)); - | --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` + | --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}` | | | required by a bound introduced by this call | note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure.rs:20:34 + --> $DIR/iter-macro-not-async-closure.rs:19:34 | LL | async fn call_async_once(f: impl AsyncFnOnce()) { | ^^^^^^^^^^^^^ required by this bound in `call_async_once` -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:31:13 +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure.rs:30:13 | LL | let x = pin!(call_async_once(f)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}` | note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure.rs:20:34 + --> $DIR/iter-macro-not-async-closure.rs:19:34 | LL | async fn call_async_once(f: impl AsyncFnOnce()) { | ^^^^^^^^^^^^^ required by this bound in `call_async_once` -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:34:5 +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure.rs:32:5 | LL | x.poll(&mut Context::from_waker(Waker::noop())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}` | note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure.rs:20:34 + --> $DIR/iter-macro-not-async-closure.rs:19:34 | LL | async fn call_async_once(f: impl AsyncFnOnce()) { | ^^^^^^^^^^^^^ required by this bound in `call_async_once` diff --git a/tests/ui/iterators/iter-macro-not-async-closure.next.stderr b/tests/ui/iterators/iter-macro-not-async-closure.next.stderr new file mode 100644 index 0000000000000..8e4df855eab56 --- /dev/null +++ b/tests/ui/iterators/iter-macro-not-async-closure.next.stderr @@ -0,0 +1,41 @@ +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure.rs:30:34 + | +LL | let x = pin!(call_async_once(f)); + | --------------- ^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}` + | | + | required by a bound introduced by this call + | +note: required by a bound in `call_async_once` + --> $DIR/iter-macro-not-async-closure.rs:19:34 + | +LL | async fn call_async_once(f: impl AsyncFnOnce()) { + | ^^^^^^^^^^^^^ required by this bound in `call_async_once` + +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure.rs:30:13 + | +LL | let x = pin!(call_async_once(f)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}` + | +note: required by a bound in `call_async_once` + --> $DIR/iter-macro-not-async-closure.rs:19:34 + | +LL | async fn call_async_once(f: impl AsyncFnOnce()) { + | ^^^^^^^^^^^^^ required by this bound in `call_async_once` + +error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}: AsyncFnOnce()` is not satisfied + --> $DIR/iter-macro-not-async-closure.rs:32:5 + | +LL | x.poll(&mut Context::from_waker(Waker::noop())); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:24:21: 24:28}` + | +note: required by a bound in `call_async_once` + --> $DIR/iter-macro-not-async-closure.rs:19:34 + | +LL | async fn call_async_once(f: impl AsyncFnOnce()) { + | ^^^^^^^^^^^^^ required by this bound in `call_async_once` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/iterators/iter-macro-not-async-closure.rs b/tests/ui/iterators/iter-macro-not-async-closure.rs index 1736423065396..e803810c618bf 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure.rs +++ b/tests/ui/iterators/iter-macro-not-async-closure.rs @@ -1,8 +1,7 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -//@[next] known-bug: trait-system-refactor-initiative#302 -//@[next] check-pass +//@check-fail // This test ensures iterators created with the `iter!` macro are not // accidentally async closures. @@ -28,9 +27,7 @@ fn main() { } }}; - let x = pin!(call_async_once(f)); - //[current]~^ ERROR AsyncFnOnce()` is not satisfied - //[current]~| ERROR AsyncFnOnce()` is not satisfied - x.poll(&mut Context::from_waker(Waker::noop())); - //[current]~^ ERROR AsyncFnOnce()` is not satisfied + let x = pin!(call_async_once(f)); //~ ERROR AsyncFnOnce()` is not satisfied + //~| ERROR AsyncFnOnce()` is not satisfied + x.poll(&mut Context::from_waker(Waker::noop())); //~ ERROR AsyncFnOnce()` is not satisfied }