Report more detailed reason why `Index` impl is not satisfied by compiler-errors...
source link: https://github.com/rust-lang/rust/pull/110432
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Collaborator
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
labels
compiler/rustc_hir_typeck/src/expr.rs
Outdated Show resolved
if let Some((_, index_ty, element_ty)) = |
||
self.find_and_report_unsatisfied_index_impl(expr.hir_id, base, base_t) |
||
{ |
||
self.demand_coerce(idx, idx_t, index_ty, None, AllowTwoPhase::No); |
Contributor
Why are we registering a coercion? To avoid ambiguities later?
Mostly just copying the confirmation logic from the happy path. Leaving it unconstrained probably isn't great, but I haven't thought much about creating additional spurious errors from this.
let errors = ocx.select_where_possible(); |
||
// There should be at least one error reported. If not, we |
||
// will still delay a span bug in `report_fulfillment_errors`. |
||
Ok::<_, NoSolution>(( |
Contributor
If we are emitting an error, why are we committing inference constraints?
Because otherwise we wouldn't be able to return a useful return type here for later typechecking to use. I guess we could return ty::Error
here or something, but I prefer recoveries to be as accurate as possible for downstream typechecking.
compiler/rustc_hir_typeck/src/expr.rs
Outdated Show resolved
compiler/rustc_hir_typeck/src/expr.rs
Outdated Show resolved
Collaborator
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Member
Author
@cjgillot, I messed with the test a bit to justify what the index ty coercion and that |
@@ -0,0 +1,27 @@ | ||
use std::hash::Hash; |
I would've marked this as // run-rustfix
but I cannot due to overlapping suggestion spans. I'll fix that in a different PR.
Contributor
Thanks! |
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Successfully merging this pull request may close these issues.
Improve error message E0608 when the type supports Index but Idx is missing trait bounds
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK