typeck: silence unreachable code from await

This commit silences the unreachable code lint when it originates from
within a await desugaring.

Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
David Wood 2019-09-30 21:27:18 +01:00
parent 22bc9e1d9c
commit 870b47fee4
No known key found for this signature in database
GPG Key ID: 2592E76C87381FD9
4 changed files with 43 additions and 1 deletions

View File

@ -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);

View File

@ -0,0 +1,12 @@
// edition:2018
#![deny(unreachable_code)]
async fn foo() {
return; bar().await;
//~^ ERROR unreachable statement
}
async fn bar() {
}
fn main() { }

View File

@ -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

View File

@ -0,0 +1,13 @@
// check-pass
// edition:2018
#![deny(unreachable_code)]
async fn foo() {
endless().await;
}
async fn endless() -> ! {
loop {}
}
fn main() { }