Skip to content

Commit

Permalink
Rollup merge of rust-lang#64930 - davidtwco:issue-61798-diverging-awa…
Browse files Browse the repository at this point in the history
…it, 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.
  • Loading branch information
Centril authored Oct 1, 2019
2 parents dc1c1fe + 870b47f commit f4aa29f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2364,7 +2364,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// which diverges, that we are about to lint on. This gives suboptimal diagnostics.
// Instead, stop here so that the `if`- or `while`-expression's block is linted instead.
if !span.is_desugaring(DesugaringKind::CondTemporary) &&
!span.is_desugaring(DesugaringKind::Async)
!span.is_desugaring(DesugaringKind::Async) &&
!orig_span.is_desugaring(DesugaringKind::Await)
{
self.diverges.set(Diverges::WarnedAlways);

Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/async-await/unreachable-lint-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// edition:2018
#![deny(unreachable_code)]

async fn foo() {
return; bar().await;
//~^ ERROR unreachable statement
}

async fn bar() {
}

fn main() { }
16 changes: 16 additions & 0 deletions src/test/ui/async-await/unreachable-lint-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: unreachable statement
--> $DIR/unreachable-lint-1.rs:5:13
|
LL | return; bar().await;
| ------ ^^^^^^^^^^^^ unreachable statement
| |
| any code following this expression is unreachable
|
note: lint level defined here
--> $DIR/unreachable-lint-1.rs:2:9
|
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error

13 changes: 13 additions & 0 deletions src/test/ui/async-await/unreachable-lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// check-pass
// edition:2018
#![deny(unreachable_code)]

async fn foo() {
endless().await;
}

async fn endless() -> ! {
loop {}
}

fn main() { }

0 comments on commit f4aa29f

Please sign in to comment.