Skip to content

Commit 4687e24

Browse files
committed
fix: break inside async closure has incorrect span for enclosing closure
1 parent ba956ef commit 4687e24

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

compiler/rustc_passes/src/loops.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
9191
}) => {
9292
let cx = match kind {
9393
hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(kind, source)) => {
94+
let fn_decl_span = match self.cx {
95+
Closure(span) => fn_decl_span.with_lo(span.lo()),
96+
_ => fn_decl_span,
97+
};
9498
Coroutine { coroutine_span: fn_decl_span, kind, source }
9599
}
96100
_ => Closure(fn_decl_span),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ error[E0267]: `break` inside `async` closure
4141
--> $DIR/break-inside-coroutine-issue-124495.rs:21: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
5050
--> $DIR/break-inside-coroutine-issue-124495.rs:23:19

0 commit comments

Comments
 (0)