Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit d52e1eb

Browse files
committed
Work around async_trait behavior
The `#[async_trait]` attribute/crate does a transformation to all async methods, which as far as i can tell removes the `&self` lifetime, so our logic to offset by 1 if `has_self == true` for both compared types has an off-by-one-error here. This didn't error out earlier, since `get_region_from_params` uses `Vec::get`, so "this index is out of bounds" is just as `None` as "this generic param is not of kind lifetime". Also this is more a workaround than a fix. I'm not sure if we can do something cleverer than "check if the last lifetim's name is `'async_trait`".
1 parent 8bcd30a commit d52e1eb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/traverse.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,17 @@ fn diff_generics(
736736
let old_count = old_gen.own_counts();
737737
let new_count = new_gen.own_counts();
738738

739+
// NEEDSWORK: proper detection of what's going on here..
740+
let was_async_trait_transformed = old_count.lifetimes > 0
741+
&& old_gen.params[old_count.lifetimes - 1].name.as_str() == "'async_trait";
742+
739743
let self_add = if old_gen.has_self && new_gen.has_self {
740-
1
744+
if was_async_trait_transformed {
745+
// async_trait transformation undoes the self lifetime?
746+
0
747+
} else {
748+
1
749+
}
741750
} else if !old_gen.has_self && !new_gen.has_self {
742751
0
743752
} else {

0 commit comments

Comments
 (0)