diff --git a/src/expand.rs b/src/expand.rs index b0ebb4c..06c4ba3 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -350,6 +350,9 @@ fn transform_block(sig: &mut Signature, block: &mut Block) { let _: () = { #(#decls)* #(#stmts)* }; }, ReturnType::Type(_, ret) => quote_spanned! {block.brace_token.span=> + if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> { + return __ret; + } let __ret: #ret = { #(#decls)* #(#stmts)* }; #[allow(unreachable_code)] __ret diff --git a/tests/test.rs b/tests/test.rs index a97af36..06c0918 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1258,3 +1258,23 @@ pub mod issue147 { } } } + +// https://github.com/dtolnay/async-trait/issues/149 +pub mod issue149 { + use async_trait::async_trait; + + pub struct Thing; + pub trait Ret {} + impl Ret for Thing {} + + pub async fn ok() -> &'static dyn Ret { + return &Thing; + } + + #[async_trait] + pub trait Trait { + async fn fail() -> &'static dyn Ret { + return &Thing; + } + } +}