-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
c35a756
to
fdd9252
Compare
Some more discussion about why I chose to improve this function rather than make |
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
fdd9252
to
3057dc6
Compare
This comment has been minimized.
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.
3057dc6
to
1deca04
Compare
There was a problem hiding this 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| { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]`. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good point - I'll change this to use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.generator_kind instead :)
@bors r+ |
📌 Commit 1deca04 has been approved by |
There was a problem hiding this 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]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good point - I'll change this to use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.generator_kind instead :)
} else { | ||
false | ||
} | ||
}; | ||
|
||
let future_trait = self.tcx.lang_items().future_trait().unwrap(); | ||
let opaque_ty_is_future = |def_id| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, done :)
It got merged so fast I didn't have time to make changes xD
…=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`
…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`
…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``
…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
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, andnote_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