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

Prepend early return to force unsize coercion #150

Merged
merged 3 commits into from
Mar 7, 2021
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
3 changes: 3 additions & 0 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}