3

Report more detailed reason why `Index` impl is not satisfied by compiler-errors...

 1 year ago
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.
neoserver,ios ssh client

Conversation

Collaborator

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

rustbot

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

Apr 16, 2023

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 rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Member

Author

@cjgillot, I messed with the test a bit to justify what the index ty coercion and that commit_if_ok is for by demonstrating some downstream errors that result from confirming this Index impl. Hope that helps a bit.

@@ -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!
@bors r+

Contributor

pushpin Commit 8d75a8f has been approved by cjgillot

It is now in the queue for this repository.

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

Apr 18, 2023

bors

merged commit 3320b2a into

rust-lang:master

Apr 19, 2023

11 checks passed

rust-timer

added a commit to rust-lang-ci/rust that referenced this pull request

Apr 19, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

cjgillot

cjgillot left review comments
Assignees

cjgillot

Labels
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

Milestone

1.71.0

Development

Successfully merging this pull request may close these issues.

Improve error message E0608 when the type supports Index but Idx is missing trait bounds

4 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK