Skip to content

Confusing error message with borrows and dyn Error #95404

Closed
@insanitybit

Description

@insanitybit

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:

  1. 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.

  2. _#14r IDK which lifetime that's referring to. I sort of suspect it's the dyn one.

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions