Skip to content

Commit d0dfda7

Browse files
committed
Insert AsyncTrait parameter prior to const parameters
1 parent 46e46dc commit d0dfda7

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/expand.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,22 @@ fn transform_block(
414414
if !is_local {
415415
self_param.bounds.extend(self_bound);
416416
}
417+
let count = standalone
418+
.generics
419+
.params
420+
.iter()
421+
.take_while(|param| {
422+
if let GenericParam::Const(_) = param {
423+
false
424+
} else {
425+
true
426+
}
427+
})
428+
.count();
417429
standalone
418430
.generics
419431
.params
420-
.push(GenericParam::Type(self_param));
432+
.insert(count, GenericParam::Type(self_param));
421433
types.push(Ident::new("Self", Span::call_site()));
422434
}
423435
}

tests/test.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#![cfg_attr(async_trait_nightly_testing, feature(specialization, const_generics))]
1+
#![cfg_attr(
2+
async_trait_nightly_testing,
3+
feature(min_specialization, min_const_generics)
4+
)]
25

36
use async_trait::async_trait;
47

@@ -1048,3 +1051,29 @@ pub mod issue129 {
10481051
}
10491052
}
10501053
}
1054+
1055+
// https://github.com/dtolnay/async-trait/issues/134
1056+
#[cfg(async_trait_nightly_testing)]
1057+
pub mod issue134 {
1058+
use async_trait::async_trait;
1059+
1060+
#[async_trait]
1061+
trait TestTrait {
1062+
async fn run<const DUMMY: bool>(self) -> ()
1063+
where
1064+
Self: Sized,
1065+
{
1066+
}
1067+
}
1068+
1069+
pub struct TestStruct;
1070+
1071+
#[async_trait]
1072+
impl TestTrait for TestStruct {
1073+
async fn run<const DUMMY: bool>(self) -> ()
1074+
where
1075+
Self: Sized,
1076+
{
1077+
}
1078+
}
1079+
}

0 commit comments

Comments
 (0)