hidden type for `impl Trait` captures lifetime that does not appear in bounds

I made a minimal reproduction here. If I remove the ‘static lifetime of the final argument, the program compiles. If I add it back, it fails. To me, it seems both should be valid.

It’s much more likely the bug is in my understanding and not the compiler though. What am I missing?

async fn not_works(&mut self, user: &str, pass: &str, app_name: &'static str) -> io::Result<()> {
    self.user = user.to_string() + app_name;
    self.pass = pass.to_string();

    self.do_stuff().await
}

async fn works(&mut self, user: &str, pass: &str, app_name: &str) -> io::Result<()> {
    self.user = user.to_string() + app_name;
    self.pass = pass.to_string();

    self.do_stuff().await
}

The error is:

error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> src/main.rs:10:86
|
10 |     async fn not_works(&mut self, user: &str, pass: &str, app_name: &'static str) -> io::Result<()> {
|                                                                                         ^^^^^^^^^^^^^^
|
note: hidden type `impl Future` captures lifetime smaller than the function body
--> src/main.rs:10:86
|
10 |     async fn not_works(&mut self, user: &str, pass: &str, app_name: &'static str) -> io::Result<()> {
|   

Leave a Comment