Skip to content

Commit

Permalink
Infer Sync+Send bound for Arc<Self> methods with default body
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 29, 2022
1 parent e5828bf commit d1a4a23
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/expand.rs
Expand Up @@ -229,23 +229,27 @@ fn transform_sig(
.push(parse_quote_spanned!(default_span=> 'async_trait));

if has_self {
let bounds = match sig.inputs.iter().next() {
let bounds: &[InferredBound] = match sig.inputs.iter().next() {
Some(FnArg::Receiver(Receiver {
reference: Some(_),
mutability: None,
..
})) => [InferredBound::Sync],
})) => &[InferredBound::Sync],
Some(FnArg::Typed(arg))
if match (arg.pat.as_ref(), arg.ty.as_ref()) {
(Pat::Ident(pat), Type::Reference(ty)) => {
pat.ident == "self" && ty.mutability.is_none()
}
if match arg.pat.as_ref() {
Pat::Ident(pat) => pat.ident == "self",
_ => false,
} =>
{
[InferredBound::Sync]
match arg.ty.as_ref() {
Type::Reference(ty) if ty.mutability.is_none() => &[InferredBound::Sync],
Type::Path(ty) if ty.path.segments.last().unwrap().ident == "Arc" => {
&[InferredBound::Sync, InferredBound::Send]
}
_ => &[InferredBound::Send],
}
}
_ => [InferredBound::Send],
_ => &[InferredBound::Send],
};

let bounds = bounds.iter().filter_map(|bound| {
Expand Down

0 comments on commit d1a4a23

Please sign in to comment.