Skip to content

Commit

Permalink
macros: silence unreachable_code warning in select! (#2678)
Browse files Browse the repository at this point in the history
Solves #2665 by adding #[allow(unreachable_code)] inside a branch
matching arm.

Co-authored-by: Alice Ryhl <alice@ryhl.io>
  • Loading branch information
blasrodri and Darksonn authored Jul 28, 2020
1 parent ff6130d commit 027351d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions tokio/src/macros/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ macro_rules! select {
}
match branch {
$(
#[allow(unreachable_code)]
$crate::count!( $($skip)* ) => {
// First, if the future has previously been
// disabled, do not poll it again. This is done
Expand Down
16 changes: 16 additions & 0 deletions tokio/tests/macros_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,25 @@ async fn many_branches() {
assert_eq!(1, num);
}

#[tokio::test]
async fn never_branch_no_warnings() {
let t = tokio::select! {
_ = async_never() => 0,
one_async_ready = one() => one_async_ready,
};
assert_eq!(t, 1);
}

async fn one() -> usize {
1
}

async fn require_mutable(_: &mut i32) {}
async fn async_noop() {}

async fn async_never() -> ! {
use tokio::time::Duration;
loop {
tokio::time::delay_for(Duration::from_millis(10)).await;
}
}

0 comments on commit 027351d

Please sign in to comment.