Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unreachable code warning for functions that return ! #265

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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