rust icon indicating copy to clipboard operation
rust copied to clipboard

fix: break inside async closure has incorrect span for enclosing closure

Open linyihai opened this issue 1 year ago • 1 comments

Fixes #124496

linyihai avatar May 13 '24 14:05 linyihai

r? @davidtwco

rustbot has assigned @davidtwco. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar May 13 '24 14:05 rustbot

Pls look into fixing this in a more general way

Hope my latest submit general enough, I haven't see other code modules, such as the hir: : CoroutineKind: : Desugared

linyihai avatar May 14 '24 07:05 linyihai

@rustbot ready

linyihai avatar May 16 '24 14:05 linyihai

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 29.3s done
#16 DONE 32.0s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
diff of stderr:

20    |                           ^^^^^^^^^^ required by this bound in `needs_async_fn`
21 
22 error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
+   --> $DIR/wrong-fn-kind.rs:9:20
24    |
24    |
25 LL |   fn needs_async_fn(_: impl async Fn()) {}
26    |                        --------------- change this to accept `FnMut` instead of `Fn`
27 ...
27 ...
28 LL |       needs_async_fn(async || {
-    |  _____--------------_--------_^
-    | |     |              in this closure
+    |       -------------- ^-------
+    |       |              |
+    |  _____|______________in this closure
+    |  _____|______________in this closure
+    | |     |
32    | |     expects `Fn` instead of `FnMut`
34 LL | |         x += 1;


The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/wrong-fn-kind/wrong-fn-kind.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/async-closures/wrong-fn-kind.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/async-closures/wrong-fn-kind.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/wrong-fn-kind" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/wrong-fn-kind/auxiliary" "--edition=2021"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0525]: expected a closure that implements the `async Fn` trait, but this closure only implements `async FnOnce`
   |
   |
LL |       needs_async_fn(move || async move {
   |       -------------- -^^^^^^
   |       |              |
   |  _____|______________this closure implements `async FnOnce`, not `async Fn`
   | |     required by a bound introduced by this call
   | |     required by a bound introduced by this call
LL | |         //~^ ERROR expected a closure that implements the `async Fn` trait, but this closure only implements `async FnOnce`
LL | |         println!("{x}");
   | |                    - closure is `async FnOnce` because it moves the variable `x` out of its environment
LL | |     });
   | |_____- the requirement to implement `async Fn` derives from here
note: required by a bound in `needs_async_fn`
  --> /checkout/tests/ui/async-await/async-closures/wrong-fn-kind.rs:5:27
   |
   |
LL | fn needs_async_fn(_: impl async Fn()) {}
   |                           ^^^^^^^^^^ required by this bound in `needs_async_fn`

error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
   |
   |
LL |   fn needs_async_fn(_: impl async Fn()) {}
   |                        --------------- change this to accept `FnMut` instead of `Fn`
...
LL |       needs_async_fn(async || {
   |       -------------- ^-------
   |  _____|______________in this closure
   | |     |
   | |     |
   | |     expects `Fn` instead of `FnMut`
LL | |         //~^ ERROR cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
LL | |         x += 1;
   | |         - mutable borrow occurs due to use of `x` in closure
   | |_____^ cannot borrow as mutable

error: aborting due to 2 previous errors

rust-log-analyzer avatar May 27 '24 03:05 rust-log-analyzer

@rustbot ready

linyihai avatar May 27 '24 13:05 linyihai

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 31.0s done
#16 DONE 37.1s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
1 error[E0282]: type annotations needed
-   --> $DIR/ambiguous-arg.rs:9:25
+   --> $DIR/ambiguous-arg.rs:9:5
3    |
- LL |       async |check, a, b| {
-    |  _________________________^
+ LL | /     async |check, a, b| {
6 LL | |
7 LL | |         temp.abs_diff(12);


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/ambiguous-arg/ambiguous-arg.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/ambiguous-arg/ambiguous-arg.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/async-closures/ambiguous-arg.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/async-closures/ambiguous-arg.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/ambiguous-arg" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/ambiguous-arg/auxiliary" "--edition=2021"
--- stderr -------------------------------
error[E0282]: type annotations needed
##[error]  --> /checkout/tests/ui/async-await/async-closures/ambiguous-arg.rs:9:5
   |
   |
LL | /     async |check, a, b| {
LL | |         //~^ ERROR type annotations needed
LL | |         temp.abs_diff(12);
   | |_____^ cannot infer type

error: aborting due to 1 previous error

---
4 LL |     let x = async || {};
-    |                      -- the expected `async` closure body
+    |             ----------- the expected `async` closure body
6 LL |
7 LL |     let () = x();
8    |         ^^   --- this expression has type `{static main::{closure#0}::{closure#0}<?17t> upvar_tys=?16t witness=?6t}`

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/def-path/def-path.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/async-closures/def-path.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/async-closures/def-path.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/def-path" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/def-path/auxiliary" "-Zverbose-internals" "--edition=2021"
--- stderr -------------------------------
error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/async-await/async-closures/def-path.rs:9:9
   |
   |
LL |     let x = async || {};
   |             ----------- the expected `async` closure body
LL |     //~^ NOTE the expected `async` closure body
LL |     let () = x();
   |         ^^   --- this expression has type `{static main::{closure#0}::{closure#0}<?17t> upvar_tys=?16t witness=?6t}`
   |         expected `async` closure body, found `()`
   |
   |
   = note: expected `async` closure body `{static main::{closure#0}::{closure#0}<?17t> upvar_tys=?16t witness=?6t}`

error: aborting due to 1 previous error

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


---- [ui] tests/ui/async-await/async-closures/is-not-fn.rs stdout ----
diff of stderr:

- error[E0271]: expected `{async [email protected]:7:14}` to be a closure that returns `()`, but it returns `{async closure body@$DIR/is-not-fn.rs:7:23: 7:25}`
+ error[E0271]: expected `{async [email protected]:7:14}` to be a closure that returns `()`, but it returns `{async closure body@$DIR/is-not-fn.rs:7:14: 7:25}`
2   --> $DIR/is-not-fn.rs:7:14
3    |
4 LL |     needs_fn(async || {});
7    |     required by a bound introduced by this call
8    |
9    = note:         expected unit type `()`
9    = note:         expected unit type `()`
-            found `async` closure body `{async closure body@$DIR/is-not-fn.rs:7:23: 7:25}`
+            found `async` closure body `{async closure body@$DIR/is-not-fn.rs:7:14: 7:25}`
11 note: required by a bound in `needs_fn`
12   --> $DIR/is-not-fn.rs:6:25


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/is-not-fn/is-not-fn.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/is-not-fn/is-not-fn.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/async-closures/is-not-fn.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/async-closures/is-not-fn.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/is-not-fn" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/is-not-fn/auxiliary" "--edition=2021"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0271]: expected `{async [email protected]:7:14}` to be a closure that returns `()`, but it returns `{async closure body@/checkout/tests/ui/async-await/async-closures/is-not-fn.rs:7:14: 7:25}`
   |
   |
LL |     needs_fn(async || {});
   |     -------- ^^^^^^^^^^^ expected `()`, found `async` closure body
   |     required by a bound introduced by this call
   |
   = note:         expected unit type `()`
   = note:         expected unit type `()`
           found `async` closure body `{async closure body@/checkout/tests/ui/async-await/async-closures/is-not-fn.rs:7:14: 7:25}`
note: required by a bound in `needs_fn`
   |
   |
LL |     fn needs_fn(x: impl FnOnce()) {}
   |                         ^^^^^^^^ required by this bound in `needs_fn`
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0271`.
------------------------------------------
---
1 error: lifetime may not live long enough
-   --> $DIR/higher-ranked-return.rs:13:46
+   --> $DIR/higher-ranked-return.rs:13:17
3    |
4 LL |           let x = async move |x: &str| -> &str {
-    |  ________________________________-________----_^
-    | |                                |        |
-    | |                                |        return type of async closure `{async closure body@$DIR/higher-ranked-return.rs:13:46: 15:10}` contains a lifetime `'2`
-    | |                                let's call the lifetime of this reference `'1`
+    |                   ^              -        ---- return type of async closure `{async closure body@$DIR/higher-ranked-return.rs:13:17: 15:10}` contains a lifetime `'2`
+    |                   |              |
+    |  _________________|              let's call the lifetime of this reference `'1`
9 LL | |             x
10 LL | |         };
10 LL | |         };
11    | |_________^ returning this value requires that `'1` must outlive `'2`

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/higher-ranked-return/higher-ranked-return.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/async-closures/higher-ranked-return.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/async-closures/higher-ranked-return.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/higher-ranked-return" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/higher-ranked-return/auxiliary" "--edition=2021"
--- stderr -------------------------------
error: lifetime may not live long enough
##[error]  --> /checkout/tests/ui/async-await/async-closures/higher-ranked-return.rs:13:17
   |
   |
LL |           let x = async move |x: &str| -> &str {
   |                   ^              -        ---- return type of async closure `{async closure body@/checkout/tests/ui/async-await/async-closures/higher-ranked-return.rs:13:17: 15:10}` contains a lifetime `'2`
   |                   |              |
   |  _________________|              let's call the lifetime of this reference `'1`
LL | |             x
LL | |         };
LL | |         };
   | |_________^ returning this value requires that `'1` must outlive `'2`
error: aborting due to 1 previous error
------------------------------------------



---- [ui] tests/ui/async-await/async-closures/not-lending.rs stdout ----
diff of stderr:

1 error: lifetime may not live long enough
-   --> $DIR/not-lending.rs:14:42
+   --> $DIR/not-lending.rs:14:17
3    |
4 LL |         let x = async move || -> &String { &s };
-    |                 ------------------------ ^^^^^^ returning this value requires that `'1` must outlive `'2`
6    |                 |                |
6    |                 |                |
-    |                 |                return type of async closure `{async closure body@$DIR/not-lending.rs:14:42: 14:48}` contains a lifetime `'2`
+    |                 |                return type of async closure `{async closure body@$DIR/not-lending.rs:14:17: 14:48}` contains a lifetime `'2`
8    |                 lifetime `'1` represents this closure's body
+    |                 returning this value requires that `'1` must outlive `'2`
9    |
10    = note: closure implements `Fn`, so references to captured variables can't escape the closure

12 error: lifetime may not live long enough
-   --> $DIR/not-lending.rs:18:31
+   --> $DIR/not-lending.rs:18:17
+   --> $DIR/not-lending.rs:18:17
14    |
15 LL |         let x = async move || { &s };
-    |                 ------------- ^^^^^^ returning this value requires that `'1` must outlive `'2`
17    |                 |           |
17    |                 |           |
-    |                 |           return type of async closure `{async closure body@$DIR/not-lending.rs:18:31: 18:37}` contains a lifetime `'2`
+    |                 |           return type of async closure `{async closure body@$DIR/not-lending.rs:18:17: 18:37}` contains a lifetime `'2`
19    |                 lifetime `'1` represents this closure's body
+    |                 returning this value requires that `'1` must outlive `'2`
20    |
21    = note: closure implements `Fn`, so references to captured variables can't escape the closure


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/not-lending/not-lending.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/not-lending/not-lending.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/async-closures/not-lending.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/async-closures/not-lending.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/not-lending" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/async-closures/not-lending/auxiliary" "--edition=2021"
--- stderr -------------------------------
error: lifetime may not live long enough
##[error]  --> /checkout/tests/ui/async-await/async-closures/not-lending.rs:14:17
   |
   |
LL |         let x = async move || -> &String { &s };
   |                 |                |
   |                 |                |
   |                 |                return type of async closure `{async closure body@/checkout/tests/ui/async-await/async-closures/not-lending.rs:14:17: 14:48}` contains a lifetime `'2`
   |                 lifetime `'1` represents this closure's body
   |                 returning this value requires that `'1` must outlive `'2`
   |
   = note: closure implements `Fn`, so references to captured variables can't escape the closure
error: lifetime may not live long enough
##[error]  --> /checkout/tests/ui/async-await/async-closures/not-lending.rs:18:17
   |
   |
LL |         let x = async move || { &s };
   |                 |           |
   |                 |           |
   |                 |           return type of async closure `{async closure body@/checkout/tests/ui/async-await/async-closures/not-lending.rs:18:17: 18:37}` contains a lifetime `'2`
   |                 lifetime `'1` represents this closure's body
   |                 returning this value requires that `'1` must outlive `'2`
   |
   = note: closure implements `Fn`, so references to captured variables can't escape the closure
error: aborting due to 2 previous errors
------------------------------------------



---- [ui] tests/ui/async-await/coroutine-desc.rs stdout ----
diff of stderr:

44    |
45 LL |     fun((async || {})(), (async || {})());
46    |     --- ---------------  ^^^^^^^^^^^^^^^ expected `async` closure body, found a different `async` closure body
-    |     |   |         |
-    |     |   |         the expected `async` closure body
+    |     |   ||
+    |     |   |the expected `async` closure body
49    |     |   expected all arguments to be this `async` closure body type because they need to match the type of this parameter
51    |


-    = note: expected `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:19: 14:21}`
-               found `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:36: 14:38}`
+    = note: expected `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:10: 14:21}`
+               found `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:27: 14:38}`
55   --> $DIR/coroutine-desc.rs:8:4
56    |



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/coroutine-desc/coroutine-desc.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/coroutine-desc.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/coroutine-desc.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/coroutine-desc" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/coroutine-desc/auxiliary" "--edition=2018"
--- stderr -------------------------------
error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/async-await/coroutine-desc.rs:10:19
   |
   |
LL |     fun(async {}, async {});
   |     --- --------  ^^^^^^^^ expected `async` block, found a different `async` block
   |     |   |
   |     |   the expected `async` block
   |     |   expected all arguments to be this `async` block type because they need to match the type of this parameter
   |
   |
   = note: expected `async` block `{async block@/checkout/tests/ui/async-await/coroutine-desc.rs:10:9: 10:17}`
              found `async` block `{async block@/checkout/tests/ui/async-await/coroutine-desc.rs:10:19: 10:27}`
  --> /checkout/tests/ui/async-await/coroutine-desc.rs:8:4
   |
   |
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
   |    ^^^ -                       -----  ----- this parameter needs to match the `async` block type of `f1`
   |        |                       |
   |        |                       `f2` needs to match the `async` block type of this parameter
   |        `f1` and `f2` all reference this parameter F
error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/async-await/coroutine-desc.rs:12:16
   |
   |
LL |     fun(one(), two());
   |     --- -----  ^^^^^ expected future, found a different future
   |     |   |
   |     |   expected all arguments to be this future type because they need to match the type of this parameter
   |
   |
   = help: consider `await`ing on both `Future`s
   = note: distinct uses of `impl Trait` result in different opaque types
  --> /checkout/tests/ui/async-await/coroutine-desc.rs:8:4
   |
   |
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
   |    ^^^ -                       -----  ----- this parameter needs to match the future type of `f1`
   |        |                       `f2` needs to match the future type of this parameter
   |        `f1` and `f2` all reference this parameter F

error[E0308]: mismatched types
error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/async-await/coroutine-desc.rs:14:26
   |
LL |     fun((async || {})(), (async || {})());
   |     --- ---------------  ^^^^^^^^^^^^^^^ expected `async` closure body, found a different `async` closure body
   |     |   ||
   |     |   |the expected `async` closure body
   |     |   expected all arguments to be this `async` closure body type because they need to match the type of this parameter
   |
   |
   = note: expected `async` closure body `{async closure body@/checkout/tests/ui/async-await/coroutine-desc.rs:14:10: 14:21}`
              found `async` closure body `{async closure body@/checkout/tests/ui/async-await/coroutine-desc.rs:14:27: 14:38}`
  --> /checkout/tests/ui/async-await/coroutine-desc.rs:8:4
   |
   |
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
   |    ^^^ -                       -----  ----- this parameter needs to match the `async` closure body type of `f1`
   |        |                       |
   |        |                       `f2` needs to match the `async` closure body type of this parameter
   |        `f1` and `f2` all reference this parameter F
error: aborting due to 3 previous errors

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


---- [ui] tests/ui/async-await/issue-74072-lifetime-name-annotations.rs stdout ----
diff of stderr:

23    |     - return type of async closure is &'1 i32
25 error: lifetime may not live long enough
-   --> $DIR/issue-74072-lifetime-name-annotations.rs:14:20
+   --> $DIR/issue-74072-lifetime-name-annotations.rs:14:6
27    |
27    |
28 LL |       (async move || {
-    |  ______-------------_^
-    | |      |           |
-    | |      |           return type of async closure `{async closure body@$DIR/issue-74072-lifetime-name-annotations.rs:14:20: 20:6}` contains a lifetime `'2`
-    | |      lifetime `'1` represents this closure's body
+    |        |           |
+    |        |           |
+    |        |           return type of async closure `{async closure body@$DIR/issue-74072-lifetime-name-annotations.rs:14:6: 20:6}` contains a lifetime `'2`
+    |  ______lifetime `'1` represents this closure's body
33 LL | |
34 LL | |
34 LL | |
35 LL | |         let y = &*x;

71    |     - return type of async closure is &'1 i32
73 error: lifetime may not live long enough
-   --> $DIR/issue-74072-lifetime-name-annotations.rs:24:28
+   --> $DIR/issue-74072-lifetime-name-annotations.rs:24:6
75    |
75    |
76 LL |       (async move || -> &i32 {
-    |  ______---------------------_^
-    | |      |                |
-    | |      |                return type of async closure `{async closure body@$DIR/issue-74072-lifetime-name-annotations.rs:24:28: 30:6}` contains a lifetime `'2`
-    | |      lifetime `'1` represents this closure's body
+    |        |                |
+    |        |                |
+    |        |                return type of async closure `{async closure body@$DIR/issue-74072-lifetime-name-annotations.rs:24:6: 30:6}` contains a lifetime `'2`
+    |  ______lifetime `'1` represents this closure's body
81 LL | |
82 LL | |
82 LL | |
83 LL | |         let y = &*x;

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issue-74072-lifetime-name-annotations/issue-74072-lifetime-name-annotations.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/issue-74072-lifetime-name-annotations.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issue-74072-lifetime-name-annotations" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issue-74072-lifetime-name-annotations/auxiliary" "--edition=2018"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0506]: cannot assign to `*x` because it is borrowed
   |
   |
LL | pub async fn async_fn(x: &mut i32) -> &i32 {
   |                          - let's call the lifetime of this reference `'1`
LL |     let y = &*x;
   |             --- `*x` is borrowed here
LL |     *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
   |     ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL |     y
   |     - returning this value requires that `*x` is borrowed for `'1`

error[E0506]: cannot assign to `*x` because it is borrowed
   |
   |
LL |         let y = &*x;
   |                 --- `*x` is borrowed here
LL |         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
   |         ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL |         y
   |         - returning this value requires that `*x` is borrowed for `'1`
LL |     })()
   |     - return type of async closure is &'1 i32
error: lifetime may not live long enough
##[error]  --> /checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs:14:6
   |
   |
LL |       (async move || {
   |        |           |
   |        |           |
   |        |           return type of async closure `{async closure body@/checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs:14:6: 20:6}` contains a lifetime `'2`
   |  ______lifetime `'1` represents this closure's body
   | |
LL | |         //~^ ERROR lifetime may not live long enough
LL | |         //~| ERROR temporary value dropped while borrowed
LL | |         let y = &*x;
LL | |         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
LL | |     })()
LL | |     })()
   | |_____^ returning this value requires that `'1` must outlive `'2`
   |
   = note: closure implements `FnMut`, so references to captured variables can't escape the closure
error[E0716]: temporary value dropped while borrowed
##[error]  --> /checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs:14:5
   |
   |
LL |    pub fn async_closure(x: &mut i32) -> impl Future<Output=&i32> {
   |                            - let's call the lifetime of this reference `'1`
LL | //     (async move || {
LL | ||         //~^ ERROR lifetime may not live long enough
LL | ||         //~| ERROR temporary value dropped while borrowed
LL | ||         let y = &*x;
LL | ||         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
LL | ||     })()
LL | ||     })()
   | ||______^_- argument requires that borrow lasts for `'1`
   |         creates a temporary value which is freed while still in use
LL |    }
   |    - temporary value is freed at the end of this statement


error[E0506]: cannot assign to `*x` because it is borrowed
   |
   |
LL |         let y = &*x;
   |                 --- `*x` is borrowed here
LL |         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
   |         ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL |         y
   |         - returning this value requires that `*x` is borrowed for `'1`
LL |     })()
   |     - return type of async closure is &'1 i32
error: lifetime may not live long enough
##[error]  --> /checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs:24:6
   |
   |
LL |       (async move || -> &i32 {
   |        |                |
   |        |                |
   |        |                return type of async closure `{async closure body@/checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs:24:6: 30:6}` contains a lifetime `'2`
   |  ______lifetime `'1` represents this closure's body
   | |
LL | |         //~^ ERROR lifetime may not live long enough
LL | |         //~| ERROR temporary value dropped while borrowed
LL | |         let y = &*x;
LL | |         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
LL | |     })()
LL | |     })()
   | |_____^ returning this value requires that `'1` must outlive `'2`
   |
   = note: closure implements `FnMut`, so references to captured variables can't escape the closure
error[E0716]: temporary value dropped while borrowed
##[error]  --> /checkout/tests/ui/async-await/issue-74072-lifetime-name-annotations.rs:24:5
   |
   |
LL |    pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future<Output=&i32> {
   |                                                 - let's call the lifetime of this reference `'1`
LL | //     (async move || -> &i32 {
LL | ||         //~^ ERROR lifetime may not live long enough
LL | ||         //~| ERROR temporary value dropped while borrowed
LL | ||         let y = &*x;
LL | ||         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
LL | ||     })()
LL | ||     })()
   | ||______^_- argument requires that borrow lasts for `'1`
   |         creates a temporary value which is freed while still in use
LL |    }
   |    - temporary value is freed at the end of this statement


error[E0506]: cannot assign to `*x` because it is borrowed
   |
   |
LL |         let y = &*x;
   |                 --- `*x` is borrowed here
LL |         *x += 1; //~ ERROR cannot assign to `*x` because it is borrowed
   |         ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL |         y
   |         - returning this value requires that `*x` is borrowed for `'1`
LL |     }
   |     - return type of async block is &'1 i32
error: aborting due to 8 previous errors

Some errors have detailed explanations: E0506, E0716.
For more information about an error, try `rustc --explain E0506`.
---
16    |
17 LL |       let async_closure = async || {
-    |  __________________________________-
+    |  _________________________-
19 LL | |         let x: Option<u32> = None;
20 LL | |         x?;
21    | |          ^ cannot use the `?` operator in an async closure that returns `u32`

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/try-on-option-in-async/try-on-option-in-async.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/try-on-option-in-async.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/try-on-option-in-async.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/try-on-option-in-async" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/try-on-option-in-async/auxiliary" "--edition=2018"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `FromResidual`)
   |
LL | /     async {
LL | |         let x: Option<u32> = None;
LL | |         let x: Option<u32> = None;
LL | |         x?; //~ ERROR the `?` operator
   | |          ^ cannot use the `?` operator in an async block that returns `{integer}`
LL | |     }
LL | |     }
   | |_____- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `{integer}`

error[E0277]: the `?` operator can only be used in an async closure that returns `Result` or `Option` (or another type that implements `FromResidual`)
   |
LL |       let async_closure = async || {
   |  _________________________-
LL | |         let x: Option<u32> = None;
LL | |         let x: Option<u32> = None;
LL | |         x?; //~ ERROR the `?` operator
   | |          ^ cannot use the `?` operator in an async closure that returns `u32`
LL | |     };
LL | |     };
   | |_____- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`

error[E0277]: the `?` operator can only be used in an async function that returns `Result` or `Option` (or another type that implements `FromResidual`)
   |
LL |   async fn an_async_function() -> u32 {
   |  _____________________________________-
LL | |     let x: Option<u32> = None;
LL | |     let x: Option<u32> = None;
LL | |     x?; //~ ERROR the `?` operator
   | |      ^ cannot use the `?` operator in an async function that returns `u32`
LL | | }
LL | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
error: aborting due to 3 previous errors

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

rust-log-analyzer avatar Jun 05 '24 10:06 rust-log-analyzer

I think it's ready to review. Would you @compiler-errors leave some feadback? I will be very appreciate for it

linyihai avatar Jun 05 '24 15:06 linyihai

@bors r+

compiler-errors avatar Jun 18 '24 15:06 compiler-errors

:pushpin: Commit 05b7b46e65207bdc33bd86c4ffda3516059e4de9 has been approved by compiler-errors

It is now in the queue for this repository.

bors avatar Jun 18 '24 15:06 bors