Skip to content

Commit cac592f

Browse files
authored
Rollup merge of rust-lang#64930 - davidtwco:issue-61798-diverging-await, r=petrochenkov
Silence unreachable code lint from await desugaring Fixes rust-lang#61798. This PR silences the unreachable code lint when it originates from within an await desugaring.
2 parents 0aaab33 + 870b47f commit cac592f

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/librustc_typeck/check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23642364
// which diverges, that we are about to lint on. This gives suboptimal diagnostics.
23652365
// Instead, stop here so that the `if`- or `while`-expression's block is linted instead.
23662366
if !span.is_desugaring(DesugaringKind::CondTemporary) &&
2367-
!span.is_desugaring(DesugaringKind::Async)
2367+
!span.is_desugaring(DesugaringKind::Async) &&
2368+
!orig_span.is_desugaring(DesugaringKind::Await)
23682369
{
23692370
self.diverges.set(Diverges::WarnedAlways);
23702371

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2018
2+
#![deny(unreachable_code)]
3+
4+
async fn foo() {
5+
return; bar().await;
6+
//~^ ERROR unreachable statement
7+
}
8+
9+
async fn bar() {
10+
}
11+
12+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: unreachable statement
2+
--> $DIR/unreachable-lint-1.rs:5:13
3+
|
4+
LL | return; bar().await;
5+
| ------ ^^^^^^^^^^^^ unreachable statement
6+
| |
7+
| any code following this expression is unreachable
8+
|
9+
note: lint level defined here
10+
--> $DIR/unreachable-lint-1.rs:2:9
11+
|
12+
LL | #![deny(unreachable_code)]
13+
| ^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
// edition:2018
3+
#![deny(unreachable_code)]
4+
5+
async fn foo() {
6+
endless().await;
7+
}
8+
9+
async fn endless() -> ! {
10+
loop {}
11+
}
12+
13+
fn main() { }

0 commit comments

Comments
 (0)