From 027351dd3a6da88d1b2ed9c687b96fa4ca8a7a6d Mon Sep 17 00:00:00 2001 From: Blas Rodriguez Irizar Date: Tue, 28 Jul 2020 22:10:07 +0200 Subject: macros: silence unreachable_code warning in select! (#2678) Solves #2665 by adding #[allow(unreachable_code)] inside a branch matching arm. Co-authored-by: Alice Ryhl --- tokio/src/macros/select.rs | 1 + tokio/tests/macros_select.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tokio/src/macros/select.rs b/tokio/src/macros/select.rs index 52c8fdd3..6497a510 100644 --- a/tokio/src/macros/select.rs +++ b/tokio/src/macros/select.rs @@ -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 diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index 6f027f3b..2ebc4efc 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -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; + } +} -- cgit v1.2.3