Description
Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=06baecf9bfb364dbe030e6009f2316f9
use std::sync::Arc;
async fn do_stuff(boop: Arc<dyn std::error::Error>, beep: &str, borp: &str){
}
The current output is:
error[[E0700]](https://doc.rust-lang.org/stable/error-index.html#E0700): hidden type for `impl Trait` captures lifetime that does not appear in bounds
[--> src/lib.rs:3:76
](https://play.rust-lang.org/#) |
3 | async fn do_stuff(boop: Arc<dyn std::error::Error>, beep: &str, borp: &str){
| ^
|
= note: hidden type `impl Future<Output = [async output]>` captures lifetime '_#14r
Ideally the output should look like:
I'm not really sure. I actually don't get why this is an error? If I remove any one of those arguments it works. I think this is a combination of dyn
with async and multiple references, although weirdly if there's only one &str it compiles... idk!
Things that are confusing:
-
There is no "impl Future" - it's hidden, but where? I know it's because async desugares to that, but I think that's confusing.
-
_#14r
IDK which lifetime that's referring to. I sort of suspect it's the dyn one. -
It doesn't tell me what to do
The code to fix this is to add a lifetime:
async fn do_stuff<'a>(boop: Box<dyn std::error::Error + 'a>, beep: &str, borp: &str){
}
So ideally it'd suggest that. An anonymous lifetime works too, actually.