From a611197f85a7e3b111aa358ad6a076121d5aa66e Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 9 Dec 2019 17:30:47 +0100 Subject: [PATCH 1/2] Remove `-Z install-upgrade` for cargo-hack This is now the default since https://github.com/rust-lang/cargo/pull/7560 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index db964a30fd..c19dd2c310 100644 --- a/.travis.yml +++ b/.travis.yml @@ -129,7 +129,7 @@ matrix: - name: cargo check (features) rust: nightly install: - - cargo install -Z install-upgrade cargo-hack + - cargo install cargo-hack script: # Check each specified feature works properly # * `--each-feature` - run for each feature which includes --no-default-features and default features of package From f57d91ae43ae9ad4e0cbcd32c9ba3e1cafdb7519 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 9 Dec 2019 18:00:36 +0100 Subject: [PATCH 2/2] Add allow(unreachable_code) for usage of try_join with the never type Fixes #1992 --- futures-macro/src/join.rs | 4 ++++ futures/tests/try_join.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 futures/tests/try_join.rs diff --git a/futures-macro/src/join.rs b/futures-macro/src/join.rs index aaedc3e3ec..93b5a28cec 100644 --- a/futures-macro/src/join.rs +++ b/futures-macro/src/join.rs @@ -129,6 +129,8 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream { } else if unsafe { #futures_crate::core_reexport::pin::Pin::new_unchecked(&mut #fut) }.output_mut().unwrap().is_err() { // `.err().unwrap()` rather than `.unwrap_err()` so that we don't introduce // a `T: Debug` bound. + // Also, for an error type of ! any code after `err().unwrap()` is unreachable. + #[allow(unreachable_code)] return #futures_crate::core_reexport::task::Poll::Ready( #futures_crate::core_reexport::result::Result::Err( unsafe { #futures_crate::core_reexport::pin::Pin::new_unchecked(&mut #fut) }.take_output().unwrap().err().unwrap() @@ -141,6 +143,8 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream { quote! { // `.ok().unwrap()` rather than `.unwrap()` so that we don't introduce // an `E: Debug` bound. + // Also, for an ok type of ! any code after `ok().unwrap()` is unreachable. + #[allow(unreachable_code)] unsafe { #futures_crate::core_reexport::pin::Pin::new_unchecked(&mut #fut) }.take_output().unwrap().ok().unwrap(), } }); diff --git a/futures/tests/try_join.rs b/futures/tests/try_join.rs new file mode 100644 index 0000000000..a148657288 --- /dev/null +++ b/futures/tests/try_join.rs @@ -0,0 +1,23 @@ +#![deny(unreachable_code)] + +use futures::{try_join, executor::block_on}; + +#[test] +fn try_join_never_error() { + block_on(async { + let future1 = async { Ok::<(), !>(()) }; + let future2 = async { Ok::<(), !>(()) }; + try_join!(future1, future2) + }) + .unwrap(); +} + +#[test] +fn try_join_never_ok() { + block_on(async { + let future1 = async { Err::(()) }; + let future2 = async { Err::(()) }; + try_join!(future1, future2) + }) + .unwrap_err(); +}