::fix_hidden_lifetime_bug

Are you getting one of the two following errors (E700)?
-
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> examples/main.rs:13:40
|
13 | fn foo<'a, 'b> (it: &'a mut &'b ()) -> impl 'a + Sized {
| ^^^^^^^^^^^^^^^
|
note: hidden type `&'a mut &'b ()` captures the lifetime `'b` as defined on the function body at 13:12
--> examples/main.rs:13:12
|
13 | fn foo<'a, 'b> (it: &'a mut &'b ()) -> impl 'a + Sized {
| ^^
fn foo<'a, 'b> (it: &'a mut &'b ()) -> impl 'a + Sized {
it
}
-
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> examples/main.rs:8:45
|
8 | async fn bar<'a> (_: &(), _: Box<dyn Send>) {
| ^
|
note: hidden type `impl Future` captures lifetime smaller than the function body
--> examples/main.rs:8:45
|
8 | async fn bar<'a> (_: &(), _: Box<dyn Send>) {
| ^
async fn bar<'a> (_: &(), _: Box<dyn Send>) {
}
-
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> examples/main.rs:4:57
|
4 | async fn baz<'a> (a: &'static (), b: &'_ (), c: &'_ ()) {
| ^
|
note: hidden type `impl Future` captures lifetime smaller than the function body
--> examples/main.rs:4:57
|
4 | async fn baz<'a> (a: &'static (), b: &'_ (), c: &'_ ()) {
| ^
async fn baz<'a> (a: &'static (), b: &'_ (), c: &'_ ()) {
}
Then you can can the attribute provided by this crate to automagically generate
an equivalent signature that soothes this grumpy compiler
Usage
-
cargo add fix_hidden_lifetime_bug, or add the following to your Cargo.toml file:
[dependencies]
fix_hidden_lifetime_bug = "x.y.z"
- where you can find the version using
cargo search fix_hidden_lifetime_bug
-
Add the following to your lib.rs file:
#[macro_use]
extern crate fix_hidden_lifetime_bug;
-
Slap a #[fix_hidden_lifetime_bug] on the problematic function:
# use ::fix_hidden_lifetime_bug::*;
#[fix_hidden_lifetime_bug] fn foo<'a, 'b>(it: &'a mut &'b ()) -> impl 'a + Sized {
it
}
# use ::fix_hidden_lifetime_bug::*;
#[fix_hidden_lifetime_bug] async fn baz<'a>(fst: &'static str, snd: &str, thrd: &str) {
}