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

Commit 71d2bb1

Browse files
committed
Auto merge of #295 - dario23:async-trait-hack, r=JohnTitor
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`".
2 parents 8bcd30a + 75875d4 commit 71d2bb1

File tree

5 files changed

+2181
-1
lines changed

5 files changed

+2181
-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 {

tests/full.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ mod full {
173173
full_test!(libc0, "libc", "0.2.28", "0.2.31", cfg!(windows));
174174
full_test!(libc1, "libc", "0.2.47", "0.2.48", true);
175175
full_test!(rmpv, "rmpv", "0.4.0", "0.4.1", false);
176+
// NOTE: this one is a regression test for the async-trait workaround (#295) mostly
177+
full_test!(async_trait, "config", "0.13.0", "0.13.1", false);
176178
// full_test!(mozjs, "mozjs", "0.2.0", "0.3.0");
177179
// full_test!(rand, "rand", "0.3.10", "0.3.16");
178180
// full_test!(serde_pre, "serde", "0.7.0", "1.0.0");

0 commit comments

Comments
 (0)