Skip to content

Commit

Permalink
Merge pull request #265 from de-vri-es/fix-unreachable-code-warning
Browse files Browse the repository at this point in the history
Fix unreachable code warning for functions that return `!`
  • Loading branch information
dtolnay committed Apr 11, 2024
2 parents 4f0b72e + c8d958d commit b683da8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
} else {
quote! {
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> {
#[allow(unreachable_code)]
return __ret;
}
#(#decls)*
Expand Down
21 changes: 20 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(
async_trait_nightly_testing,
feature(impl_trait_in_assoc_type, min_specialization)
feature(impl_trait_in_assoc_type, min_specialization, never_type)
)]
#![deny(rust_2021_compatibility, unused_qualifications)]
#![allow(
Expand Down Expand Up @@ -252,6 +252,25 @@ pub async fn test_unimplemented() {
let _ = <() as Trait>::f;
}

#[cfg(async_trait_nightly_testing)]
pub async fn test_divering_function() {
#[async_trait]
pub trait Trait {
async fn f() -> !;
}

#[async_trait]
impl Trait for () {
async fn f() -> ! {
loop {
std::thread::sleep(std::time::Duration::from_millis(1));
}
}
}

let _ = <() as Trait>::f;
}

// https://github.com/dtolnay/async-trait/issues/1
pub mod issue1 {
use async_trait::async_trait;
Expand Down

0 comments on commit b683da8

Please sign in to comment.