Skip to content

Commit b8cade7

Browse files
committed
fix: break inside async closure has incorrect span for enclosing closure
1 parent a330e49 commit b8cade7

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10791079
let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments(
10801080
&inner_decl,
10811081
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
1082-
body.span,
1082+
body.span.with_lo(fn_decl_span.lo()),
10831083
coroutine_kind,
10841084
hir::CoroutineSource::Closure,
10851085
);

tests/ui/async-await/async-closures/wrong-fn-kind.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ LL | fn needs_async_fn(_: impl async Fn()) {}
2020
| ^^^^^^^^^^ required by this bound in `needs_async_fn`
2121

2222
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
23-
--> $DIR/wrong-fn-kind.rs:9:29
23+
--> $DIR/wrong-fn-kind.rs:9:20
2424
|
2525
LL | fn needs_async_fn(_: impl async Fn()) {}
2626
| --------------- change this to accept `FnMut` instead of `Fn`
2727
...
2828
LL | needs_async_fn(async || {
29-
| _____--------------_--------_^
30-
| | | |
31-
| | | in this closure
29+
| -------------- ^-------
30+
| | |
31+
| _____|______________in this closure
32+
| | |
3233
| | expects `Fn` instead of `FnMut`
3334
LL | |
3435
LL | | x += 1;

tests/ui/coroutine/break-inside-coroutine-issue-124495.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async gen fn async_gen_fn() {
1818

1919
fn main() {
2020
let _ = async { break; }; //~ ERROR `break` inside `async` block
21+
2122
let _ = async || { break; }; //~ ERROR `break` inside `async` closure
2223

2324
let _ = gen { break; }; //~ ERROR `break` inside `gen` block

tests/ui/coroutine/break-inside-coroutine-issue-124495.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ LL | let _ = async { break; };
3838
| enclosing `async` block
3939

4040
error[E0267]: `break` inside `async` closure
41-
--> $DIR/break-inside-coroutine-issue-124495.rs:21:24
41+
--> $DIR/break-inside-coroutine-issue-124495.rs:22:24
4242
|
4343
LL | let _ = async || { break; };
44-
| --^^^^^---
45-
| | |
46-
| | cannot `break` inside `async` closure
47-
| enclosing `async` closure
44+
| -----------^^^^^---
45+
| | |
46+
| | cannot `break` inside `async` closure
47+
| enclosing `async` closure
4848

4949
error[E0267]: `break` inside `gen` block
50-
--> $DIR/break-inside-coroutine-issue-124495.rs:23:19
50+
--> $DIR/break-inside-coroutine-issue-124495.rs:24:19
5151
|
5252
LL | let _ = gen { break; };
5353
| ------^^^^^---
@@ -56,7 +56,7 @@ LL | let _ = gen { break; };
5656
| enclosing `gen` block
5757

5858
error[E0267]: `break` inside `async gen` block
59-
--> $DIR/break-inside-coroutine-issue-124495.rs:25:25
59+
--> $DIR/break-inside-coroutine-issue-124495.rs:26:25
6060
|
6161
LL | let _ = async gen { break; };
6262
| ------------^^^^^---

0 commit comments

Comments
 (0)