Skip to content

Commit

Permalink
Merge pull request #150 from dtolnay/coercion
Browse files Browse the repository at this point in the history
Prepend early return to force unsize coercion
  • Loading branch information
dtolnay authored Mar 7, 2021
2 parents 2c4cde7 + 3596fe7 commit b332e5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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;
}
}
}

0 comments on commit b332e5c

Please sign in to comment.