Crate fix_hidden_lifetime_bug[−][src]
Expand description
::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 { | ^^
Problematic code
ⓘ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>) { | ^
Problematic code
ⓘ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: &'_ ()) { | ^
Problematic code
ⓘ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 yourCargo.toml
file:[dependencies] fix_hidden_lifetime_bug = "x.y.z"
- where you can find the version using
cargo search fix_hidden_lifetime_bug
- where you can find the version using
-
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:#[fix_hidden_lifetime_bug] // <-- Add this! fn foo<'a, 'b>(it: &'a mut &'b ()) -> impl 'a + Sized { it }
#[fix_hidden_lifetime_bug] // <-- Add this! async fn baz<'a>(fst: &'static str, snd: &str, thrd: &str) { /* … */ }
Re-exports
pub use proc_macros::*; |
Traits
Captures |