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

Don't suggest certain fixups (.field, .await, etc) when reporting errors while matching on arrays #91098

Merged
merged 2 commits into from
Nov 21, 2021

Conversation

compiler-errors
Copy link
Member

When we have a type mismatch with a cause.code that is an ObligationCauseCode::Pattern, skip suggesting fixes like adding .await or accessing a struct's .field if the pattern's root_ty differs from the expected ty. This occurs in situations like this:

struct S(());

fn main() {
    let array = [S(())];
    
    match array {
        [()] => {}
        _ => {}
    }
}

I think what's happening here is a layer of [_; N] is peeled off of both types and we end up seeing the mismatch between just S and (), but when we suggest a fixup, that applies to the expression with type root_ty.


Questions:

  1. Should this check live here, above all of the suggestions, or should I push this down into every suggestion when we match ObligationCauseCode?
  2. Any other ObligationCauseCodes to check here?
  3. Am I overlooking an easier way to get to this same conclusion without pattern matching on ObligationCauseCode and comparing root_ty?

Fixes #91058

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 21, 2021
@compiler-errors
Copy link
Member Author

r? @estebank

(I feel like I've put a lot of PRs in your queue, but thanks for all the help.)

@estebank
Copy link
Contributor

The checks look right. I would normally push the check into the methods but that would make you add args to one of them. I think this is fine as is.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 21, 2021

📌 Commit 01b2404 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 Nov 21, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2021
…askrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#91008 (Adds IEEE 754-2019 minimun and maximum functions for f32/f64)
 - rust-lang#91070 (Make `LLVMRustGetOrInsertGlobal` always return a `GlobalVariable`)
 - rust-lang#91097 (Add spaces in opaque `impl Trait` with more than one trait)
 - rust-lang#91098 (Don't suggest certain fixups (`.field`, `.await`, etc) when reporting errors while matching on arrays )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a54eae9 into rust-lang:master Nov 21, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 21, 2021
@compiler-errors compiler-errors deleted the issue-91058 branch December 3, 2021 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Erroneous suggestion to add .field when matching arrays
6 participants