Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message with borrows and dyn Error #95404

Closed
insanitybit opened this issue Mar 28, 2022 · 2 comments
Closed

Confusing error message with borrows and dyn Error #95404

insanitybit opened this issue Mar 28, 2022 · 2 comments
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@insanitybit
Copy link

insanitybit commented Mar 28, 2022

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.

@insanitybit insanitybit added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 28, 2022
@estebank estebank added A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area A-lifetimes Area: Lifetimes / regions labels Mar 28, 2022
@eholk
Copy link
Contributor

eholk commented Apr 11, 2022

We talked about this in our triage meeting today. This sounds like the same issue as #63033, so we can probably close it as a duplicate.

It looks like what's going on is that the boop parameter would normally be Box<dyn std::error::Error + 'static>, but the compiler finds an opportunity for subtyping with the future and changes it to Box<dyn std::error::Error + 'a>, but then it needs to pick a value for 'a. It doesn't want to introduce a new lifetime, so instead it needs to choose between beep (call that 'b) and borp (call that 'c). Since 'b and 'c have the same constraints, there's no best choice between these two and the compiler gives up.

Fixing #63033 should fix this one too.

@rustbot label AsyncAwait-Triaged

@rustbot rustbot added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Apr 11, 2022
@aliemjay
Copy link
Member

Thai no longer an error, fixed along with #63033.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants