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

Diagnostic involving the type of an async block refers to generator's #81457

Closed
guswynn opened this issue Jan 28, 2021 · 2 comments · Fixed by #81496
Closed

Diagnostic involving the type of an async block refers to generator's #81457

guswynn opened this issue Jan 28, 2021 · 2 comments · Fixed by #81496
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@guswynn
Copy link
Contributor

guswynn commented Jan 28, 2021

version 1.49:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6cf5c01427a274fed3395916ea86ab87

FuturesUnordered requires futures with the same type:

use futures::stream::FuturesUnordered;
fn main() {

    let u = FuturesUnordered::new();
    
    u.push(async {});
    u.push(async {});
    
}

results in:

error[E0308]: mismatched types
  --> src/main.rs:12:18
   |
11 |     u.push(async {});
   |                  -- the expected generator
12 |     u.push(async {});
   |                  ^^ expected generator, found a different generator
   |
   = note: expected generator `[static generator@src/main.rs:11:18: 11:20]`
              found generator `[static generator@src/main.rs:12:18: 12:20]`

As far as I know, generators have 2 types in their internal representation, so their display impl (its not actually display as far as I remember, but whatever creates the string to describe a type), should me more accurate about it being a future

also, these spans seem off?

@rustbot label +A-async-await +A-diagnostics +D-papercut

@rustbot rustbot added A-async-await Area: Async & Await D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jan 28, 2021
@guswynn guswynn changed the title Diagnostic involving the type of an async Diagnostic involving the type of an async block refers to generator's Jan 28, 2021
@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 28, 2021
@tmandry tmandry added AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jan 28, 2021
@tmandry tmandry removed the E-help-wanted Call for participation: Help is requested to fix this issue. label Jan 28, 2021
@estebank
Copy link
Contributor

The spans are correct (or at least consistent with what I'd expect and what we do in similar cases not involving generators/futures).

I would be in favor of carrying metadata in the generator types (do we do that already?) to differentiate between non-futures and futures and use a different user visible textual representation.

@guswynn
Copy link
Contributor Author

guswynn commented Jan 28, 2021

Yeah we do carry that metadata (in the hir::Ty). I have a local commit to clean this up but i have a bit more refactoring to do to make it look right (turns out TypeError is quite complicated haha)

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 18, 2021
…-obk

name async generators something more human friendly in type error diagnostic

fixes rust-lang#81457

Some details:

1. I opted to load the generator kind from the hir in TyCategory. I also use 1 impl in the hir for the descr
2. I named both the source of the future, in addition to the general type (`future`), not sure what is preferred
3. I am not sure what is required to make sure "generator" is not referred to anywhere. A brief `rg "\"generator\"" showed me that most diagnostics correctly distinguish from generators and async generator, but the `descr` of `DefKind` is pretty general (not sure how thats used)
4. should the descr impl of AsyncGeneratorKind use its display impl instead of copying the string?
@bors bors closed this as completed in f468fd1 Feb 19, 2021
@tmandry tmandry moved this to Done in wg-async work Dec 8, 2022
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 AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants