Skip to content

Commit abc3e4d

Browse files
KaiJewsonandrewhickman
authored andcommitted
Use async move block to fix borrowing issues
1 parent 6743972 commit abc3e4d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn context(args: TokenStream, input: TokenStream) -> TokenStream {
7171
}
7272
syn::ReturnType::Type(_, return_ty) => {
7373
input.block.stmts = syn::parse_quote!(
74-
let result: #return_ty = async { #body }.await;
74+
let result: #return_ty = async move { #body }.await;
7575
result.map_err(|err| err.context(format!(#args)).into())
7676
);
7777
}

tests/async_borrowing.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use fn_error_context::context;
2+
3+
#[context("context")]
4+
async fn borrows(val: &mut u32) -> anyhow::Result<&u32> {
5+
Ok(&*val)
6+
}
7+
8+
fn main() {
9+
}

tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ fn tests() {
1717
tests.pass("tests/fmt_named_arg.rs");
1818
tests.compile_fail("tests/async_without_return.rs");
1919
tests.compile_fail("tests/preserve_lint.rs");
20+
tests.pass("tests/async_borrowing.rs");
2021
}

0 commit comments

Comments
 (0)