Skip to content

Commit 456e64d

Browse files
authored
Merge pull request #4 from dtolnay/where
Work around `where <T>` parser restriction
2 parents 60e939f + 9c6cd9c commit 456e64d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/expand.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ fn transform_block(context: Context, sig: &MethodSig, block: &mut Block) {
282282
_ => {}
283283
}
284284

285+
if let Some(where_clause) = &mut standalone.decl.generics.where_clause {
286+
// Work around an input bound like `where Self::Output: Send` expanding
287+
// to `where <AsyncTrait>::Output: Send` which is illegal syntax because
288+
// `where<T>` is reserved for future use... :(
289+
where_clause.predicates.insert(0, parse_quote!((): Sized));
290+
}
291+
285292
let mut replace = match context {
286293
Context::Trait { .. } => ReplaceReceiver::with(parse_quote!(AsyncTrait)),
287294
Context::Impl { receiver, as_trait } => {

tests/test.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
use async_trait::async_trait;
44

5+
// Renaming to avoid masking missing absolute paths in generated code.
6+
use std::future::Future as StdFuture;
7+
58
#[async_trait]
69
trait Trait {
710
type Assoc;
@@ -115,3 +118,16 @@ pub async fn test_object_safe_with_default() {
115118
let object = &Struct as &dyn ObjectSafe;
116119
object.f().await;
117120
}
121+
122+
// https://github.com/dtolnay/async-trait/issues/2
123+
#[async_trait]
124+
pub trait Issue2: StdFuture {
125+
async fn flatten(self) -> <<Self as StdFuture>::Output as StdFuture>::Output
126+
where
127+
Self::Output: StdFuture + Send,
128+
Self: Sized,
129+
{
130+
let nested_future = self.await;
131+
nested_future.await
132+
}
133+
}

0 commit comments

Comments
 (0)