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

Commit

Permalink
Work around async_trait behavior
Browse files Browse the repository at this point in the history
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`".
  • Loading branch information
dario23 committed May 13, 2022
1 parent 40325ee commit c50f38d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,17 @@ fn diff_generics(
let old_count = old_gen.own_counts();
let new_count = new_gen.own_counts();

// NEEDSWORK: proper detection of what's going on here..
let was_async_trait_transformed = old_count.lifetimes > 0
&& old_gen.params[old_count.lifetimes - 1].name.as_str() == "'async_trait";

let self_add = if old_gen.has_self && new_gen.has_self {
1
if was_async_trait_transformed {
// async_trait transformation undoes the self lifetime?
0
} else {
1
}
} else if !old_gen.has_self && !new_gen.has_self {
0
} else {
Expand Down

0 comments on commit c50f38d

Please sign in to comment.