Skip to content

Commit b332e5c

Browse files
authored
Merge pull request #150 from dtolnay/coercion
Prepend early return to force unsize coercion
2 parents 2c4cde7 + 3596fe7 commit b332e5c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/expand.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ fn transform_block(sig: &mut Signature, block: &mut Block) {
350350
let _: () = { #(#decls)* #(#stmts)* };
351351
},
352352
ReturnType::Type(_, ret) => quote_spanned! {block.brace_token.span=>
353+
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> {
354+
return __ret;
355+
}
353356
let __ret: #ret = { #(#decls)* #(#stmts)* };
354357
#[allow(unreachable_code)]
355358
__ret

tests/test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,3 +1258,23 @@ pub mod issue147 {
12581258
}
12591259
}
12601260
}
1261+
1262+
// https://github.com/dtolnay/async-trait/issues/149
1263+
pub mod issue149 {
1264+
use async_trait::async_trait;
1265+
1266+
pub struct Thing;
1267+
pub trait Ret {}
1268+
impl Ret for Thing {}
1269+
1270+
pub async fn ok() -> &'static dyn Ret {
1271+
return &Thing;
1272+
}
1273+
1274+
#[async_trait]
1275+
pub trait Trait {
1276+
async fn fail() -> &'static dyn Ret {
1277+
return &Thing;
1278+
}
1279+
}
1280+
}

0 commit comments

Comments
 (0)