From 643c07c0d132a1b0cac930f3de8f08509c424150 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 28 Nov 2022 23:31:25 -0800 Subject: [PATCH] Generalize support for inferred multiple bounds --- src/expand.rs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/expand.rs b/src/expand.rs index 4cc4243..6214355 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -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)) => { @@ -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() {