Skip to content

Commit 6354d7f

Browse files
authored
Merge pull request #49 from Marwes/better_trait_error
fix: Make "Send is not implemented" errors point to the block
2 parents 7dcc632 + 1b9cb79 commit 6354d7f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/expand.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,22 @@ fn transform_block(
412412
Box::pin(#inner::<#(#types),*>(#(#args),*))
413413
});
414414

415+
// Make the span `Box::pin` be that of the block so that "Send is not implemented" errors point
416+
// to the block and no the `#[async_trait]` attribute
417+
if let Some(syn::Stmt::Expr(syn::Expr::Call(box_pin))) = block.stmts.last_mut() {
418+
struct ReplaceSpan(Span);
419+
impl VisitMut for ReplaceSpan {
420+
fn visit_span_mut(&mut self, span: &mut Span) {
421+
*span = self.0
422+
}
423+
}
424+
let mut replace_span = ReplaceSpan(brace.span);
425+
replace_span.visit_expr_mut(&mut box_pin.func);
426+
box_pin.paren_token.span = brace.span;
427+
} else {
428+
unreachable!()
429+
}
430+
415431
block.brace_token = brace;
416432
}
417433

0 commit comments

Comments
 (0)