Skip to content

Commit 643c07c

Browse files
committed
Generalize support for inferred multiple bounds
1 parent 6c13d6f commit 643c07c

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/expand.rs

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

231231
if has_self {
232-
let bound = match sig.inputs.iter().next() {
232+
let bounds = 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))
239239
if match (arg.pat.as_ref(), arg.ty.as_ref()) {
240240
(Pat::Ident(pat), Type::Reference(ty)) => {
@@ -243,23 +243,30 @@ fn transform_sig(
243243
_ => false,
244244
} =>
245245
{
246-
InferredBound::Sync
246+
[InferredBound::Sync]
247247
}
248-
_ => InferredBound::Send,
248+
_ => [InferredBound::Send],
249249
};
250250

251-
let assume_bound = match context {
252-
Context::Trait { supertraits, .. } => !has_default || has_bound(supertraits, &bound),
253-
Context::Impl { .. } => true,
254-
};
255-
256-
let where_clause = where_clause_or_default(&mut sig.generics.where_clause);
257-
where_clause.predicates.push(if assume_bound || is_local {
258-
parse_quote_spanned!(default_span=> Self: 'async_trait)
259-
} else {
260-
let bound = bound.spanned_path(default_span);
261-
parse_quote_spanned!(default_span=> Self: #bound + 'async_trait)
251+
let bounds = bounds.iter().filter_map(|bound| {
252+
let assume_bound = match context {
253+
Context::Trait { supertraits, .. } => {
254+
!has_default || has_bound(supertraits, bound)
255+
}
256+
Context::Impl { .. } => true,
257+
};
258+
if assume_bound || is_local {
259+
None
260+
} else {
261+
Some(bound.spanned_path(default_span))
262+
}
262263
});
264+
265+
where_clause_or_default(&mut sig.generics.where_clause)
266+
.predicates
267+
.push(parse_quote_spanned! {default_span=>
268+
Self: #(#bounds +)* 'async_trait
269+
});
263270
}
264271

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

0 commit comments

Comments
 (0)