Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize support for inferred multiple bounds #222

Merged
merged 1 commit into from Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/expand.rs
Expand Up @@ -229,12 +229,12 @@ fn transform_sig(
.push(parse_quote_spanned!(default_span=> 'async_trait));

if has_self {
let bound = match sig.inputs.iter().next() {
let bounds = 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)) => {
Expand All @@ -243,23 +243,30 @@ fn transform_sig(
_ => false,
} =>
{
InferredBound::Sync
[InferredBound::Sync]
}
_ => InferredBound::Send,
_ => [InferredBound::Send],
};

let assume_bound = match context {
Context::Trait { supertraits, .. } => !has_default || has_bound(supertraits, &bound),
Context::Impl { .. } => true,
};

let where_clause = where_clause_or_default(&mut sig.generics.where_clause);
where_clause.predicates.push(if assume_bound || is_local {
parse_quote_spanned!(default_span=> Self: 'async_trait)
} else {
let bound = bound.spanned_path(default_span);
parse_quote_spanned!(default_span=> Self: #bound + 'async_trait)
let bounds = bounds.iter().filter_map(|bound| {
let assume_bound = match context {
Context::Trait { supertraits, .. } => {
!has_default || has_bound(supertraits, bound)
}
Context::Impl { .. } => true,
};
if assume_bound || is_local {
None
} else {
Some(bound.spanned_path(default_span))
}
});

where_clause_or_default(&mut sig.generics.where_clause)
.predicates
.push(parse_quote_spanned! {default_span=>
Self: #(#bounds +)* 'async_trait
});
}

for (i, arg) in sig.inputs.iter_mut().enumerate() {
Expand Down