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

Greatly improve error reporting for futures and generators in note_obligation_cause_code #98259

Merged
merged 1 commit into from
Jun 24, 2022

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Jun 19, 2022

Most futures don't go through this code path, because they're caught by
maybe_note_obligation_cause_for_async_await. But all generators do,
and maybe_note is imperfect and doesn't catch all futures. Improve the error message for those it misses.

At some point, we may want to consider unifying this with the code for maybe_note_async_await,
so that async_await notes all parent constraints, and note_obligation can point to yield points.
But both functions are quite complicated, and it's not clear to me how to combine them;
this seems like a good incremental improvement.

Helps with #97332.

r? @estebank cc @eholk @compiler-errors

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-coroutines Area: Coroutines A-async-await Area: Async & Await labels Jun 19, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2022
@jyn514 jyn514 force-pushed the improve-obligation-errors branch from c35a756 to fdd9252 Compare June 19, 2022 19:39
@jyn514
Copy link
Member Author

jyn514 commented Jun 19, 2022

Some more discussion about why I chose to improve this function rather than make maybe_note_async_await smarter: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/josh.20rambles.20about.20drop.20tracking.20.2397332/near/286660618

@rust-log-analyzer

This comment has been minimized.

…bligation_cause_code`

Most futures don't go through this code path, because they're caught by
`maybe_note_obligation_cause_for_async_await`. But all generators do,
and `maybe_note` is imperfect and doesn't catch all futures. Improve the error message for those it misses.

At some point, we may want to consider unifying this with the code for `maybe_note_async_await`,
so that `async_await` notes all parent constraints, and `note_obligation` can point to yield points.
But both functions are quite complicated, and it's not clear to me how to combine them;
this seems like a good incremental improvement.
@jyn514 jyn514 force-pushed the improve-obligation-errors branch from 3057dc6 to 1deca04 Compare June 19, 2022 20:31
Copy link
Contributor

@eholk eholk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a significant improvement! It seems like quite a few error messages are clearer now. I left a couple comments, but they are just potential cleanups and clarification questions.

The output for the complex spans with drop tracking option looks okay to me. It's not exactly the same as without, but I think it's still clear enough what's wrong.

Anyway, I think the change looks good.

} else {
false
}
};

let future_trait = self.tcx.lang_items().future_trait().unwrap();
let opaque_ty_is_future = |def_id| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth lifting this out into a method on tcx? It seems like code that might be useful elsewhere too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done :)

ty::Generator(def_id, _, movability) => {
let sp = self.tcx.def_span(def_id);

// Special-case this to say "async block" instead of `[static generator]`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always true that a static generator is an async block? I guess it probably is for current stable Rust.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 22, 2022

📌 Commit 1deca04 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 22, 2022
Copy link
Member Author

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to address the comments and then I saw @estebank already approved the PR 😁 I'll make a new PR

ty::Generator(def_id, _, movability) => {
let sp = self.tcx.def_span(def_id);

// Special-case this to say "async block" instead of `[static generator]`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
false
}
};

let future_trait = self.tcx.lang_items().future_trait().unwrap();
let opaque_ty_is_future = |def_id| {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done :)

jyn514 added a commit to jyn514/rust that referenced this pull request Jun 22, 2022
It got merged so fast I didn't have time to make changes xD
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
…=estebank

Greatly improve error reporting for futures and generators in `note_obligation_cause_code`

Most futures don't go through this code path, because they're caught by
`maybe_note_obligation_cause_for_async_await`. But all generators do,
and `maybe_note` is imperfect and doesn't catch all futures. Improve the error message for those it misses.

At some point, we may want to consider unifying this with the code for `maybe_note_async_await`,
so that `async_await` notes all parent constraints, and `note_obligation` can point to yield points.
But both functions are quite complicated, and it's not clear to me how to combine them;
this seems like a good incremental improvement.

Helps with rust-lang#97332.

r? `@estebank` cc `@eholk` `@compiler-errors`
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
…view-comments, r=eholk

Address review comments from rust-lang#98259

It got approved so fast I didn't have time to make changes xD

r? `@eholk`
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
…view-comments, r=eholk

Address review comments from rust-lang#98259

It got approved so fast I didn't have time to make changes xD

r? ``@eholk``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 24, 2022
…piler-errors

Rollup of 16 pull requests

Successful merges:

 - rust-lang#96173 (Fix documentation for  `with_capacity` and `reserve` families of methods)
 - rust-lang#98184 (Give name if anonymous region appears in impl signature)
 - rust-lang#98259 (Greatly improve error reporting for futures and generators in `note_obligation_cause_code`)
 - rust-lang#98269 (Provide a `PathSegment.res` in more cases)
 - rust-lang#98283 (Point at private fields in struct literal)
 - rust-lang#98305 (prohibit_generics: don't alloc error string if no error emitted)
 - rust-lang#98310 (rustdoc: optimize loading of source sidebar)
 - rust-lang#98353 (Migrate two diagnostics from the `rustc_builtin_macros` crate)
 - rust-lang#98355 (Update no_default_libraries handling for emscripten target)
 - rust-lang#98364 (clarify Arc::clone overflow check comment)
 - rust-lang#98365 (Address review comments from rust-lang#98259)
 - rust-lang#98388 (implement `iter_projections` function on `PlaceRef`)
 - rust-lang#98390 (Fixes handling of keywords in rustdoc json output)
 - rust-lang#98409 (triagebot.toml: Allow applying nominated labels)
 - rust-lang#98410 (Update books)
 - rust-lang#98422 (Update browser-ui-test version to 0.9.6)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 413e350 into rust-lang:master Jun 24, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 24, 2022
@jyn514 jyn514 deleted the improve-obligation-errors branch February 25, 2023 18:32
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-coroutines Area: Coroutines A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants