Skip to content

Commit d1a4a23

Browse files
committed
Infer Sync+Send bound for Arc<Self> methods with default body
1 parent e5828bf commit d1a4a23

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/expand.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,27 @@ fn transform_sig(
229229
.push(parse_quote_spanned!(default_span=> 'async_trait));
230230

231231
if has_self {
232-
let bounds = match sig.inputs.iter().next() {
232+
let bounds: &[InferredBound] = match sig.inputs.iter().next() {
233233
Some(FnArg::Receiver(Receiver {
234234
reference: Some(_),
235235
mutability: None,
236236
..
237-
})) => [InferredBound::Sync],
237+
})) => &[InferredBound::Sync],
238238
Some(FnArg::Typed(arg))
239-
if match (arg.pat.as_ref(), arg.ty.as_ref()) {
240-
(Pat::Ident(pat), Type::Reference(ty)) => {
241-
pat.ident == "self" && ty.mutability.is_none()
242-
}
239+
if match arg.pat.as_ref() {
240+
Pat::Ident(pat) => pat.ident == "self",
243241
_ => false,
244242
} =>
245243
{
246-
[InferredBound::Sync]
244+
match arg.ty.as_ref() {
245+
Type::Reference(ty) if ty.mutability.is_none() => &[InferredBound::Sync],
246+
Type::Path(ty) if ty.path.segments.last().unwrap().ident == "Arc" => {
247+
&[InferredBound::Sync, InferredBound::Send]
248+
}
249+
_ => &[InferredBound::Send],
250+
}
247251
}
248-
_ => [InferredBound::Send],
252+
_ => &[InferredBound::Send],
249253
};
250254

251255
let bounds = bounds.iter().filter_map(|bound| {

0 commit comments

Comments
 (0)