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

Fix escaping inference var ICE in point_at_expr_source_of_inferred_type #107175

Merged
merged 2 commits into from
Jan 26, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jan 21, 2023

Fixes #107158

point_at_expr_source_of_inferred_type uses lookup_probe to adjust the self type of a method receiver -- but that method returns inference variables from inside a probe. That means that the ty vars are no longer valid, so we can't use any infcx methods on them.

Also, pass some extra span info to hack a quick solution to bad labels, resulting in this diagnostic improvement:

fn example2() {
    let mut x = vec![1];
    x.push("");
}
  error[E0308]: mismatched types
   --> src/main.rs:5:12
    |
  5 |     x.push("");
    |       ---- ^^
    |       |    |
    |       |    expected integer, found `&str`
-   |       |    this is of type `&'static str`, which causes `x` to be inferred as `Vec<{integer}>`
    |       arguments to this method are incorrect

(since that "which causes x to be inferred as Vec<{integer}> part is wrong)

r? @estebank

(we really should make this code better in general, cc #106590, but that's a bit bigger issue that needs some more thinking about)

@rustbot 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 Jan 21, 2023
Comment on lines 413 to 419
if !span.overlaps(mismatch_span) {
err.span_label(
span,
with_forced_trimmed_paths!(format!(
"here the type of `{ident}` is inferred to be `{ty}`",
)),
);
);}
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting

Copy link
Member Author

Choose a reason for hiding this comment

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

Love let-chains 🙃

@@ -0,0 +1,20 @@
// The error message here still is pretty confusing.
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably check how many spans we have and if there's only one, with infer vars in the type, then we skip the customization? Not necessary for this PR.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

r=me after fixing formatting

@compiler-errors
Copy link
Member Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Jan 23, 2023

📌 Commit 9f933b5 has been approved by estebank

It is now in the queue for this repository.

@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 Jan 23, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 23, 2023
…ush, r=estebank

Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`

Fixes rust-lang#107158

`point_at_expr_source_of_inferred_type` uses `lookup_probe` to adjust the self type of a method receiver -- but that method returns inference variables from inside a probe. That means that the ty vars are no longer valid, so we can't use any infcx methods on them.

Also, pass some extra span info to hack a quick solution to bad labels, resulting in this diagnostic improvement:

```rust
fn example2() {
    let mut x = vec![1];
    x.push("");
}
```

```diff
  error[E0308]: mismatched types
   --> src/main.rs:5:12
    |
  5 |     x.push("");
    |       ---- ^^
    |       |    |
    |       |    expected integer, found `&str`
-   |       |    this is of type `&'static str`, which causes `x` to be inferred as `Vec<{integer}>`
    |       arguments to this method are incorrect
```
(since that "which causes `x` to be inferred as `Vec<{integer}>` part is wrong)

r? `@estebank`

(we really should make this code better in general, cc rust-lang#106590, but that's a bit bigger issue that needs some more thinking about)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 25, 2023
…ush, r=estebank

Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`

Fixes rust-lang#107158

`point_at_expr_source_of_inferred_type` uses `lookup_probe` to adjust the self type of a method receiver -- but that method returns inference variables from inside a probe. That means that the ty vars are no longer valid, so we can't use any infcx methods on them.

Also, pass some extra span info to hack a quick solution to bad labels, resulting in this diagnostic improvement:

```rust
fn example2() {
    let mut x = vec![1];
    x.push("");
}
```

```diff
  error[E0308]: mismatched types
   --> src/main.rs:5:12
    |
  5 |     x.push("");
    |       ---- ^^
    |       |    |
    |       |    expected integer, found `&str`
-   |       |    this is of type `&'static str`, which causes `x` to be inferred as `Vec<{integer}>`
    |       arguments to this method are incorrect
```
(since that "which causes `x` to be inferred as `Vec<{integer}>` part is wrong)

r? ``@estebank``

(we really should make this code better in general, cc rust-lang#106590, but that's a bit bigger issue that needs some more thinking about)
@compiler-errors
Copy link
Member Author

@bors rollup as this only affects diagnostics

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2023
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#106407 (Improve proc macro attribute diagnostics)
 - rust-lang#106960 (Teach parser to understand fake anonymous enum syntax)
 - rust-lang#107085 (Custom MIR: Support binary and unary operations)
 - rust-lang#107086 (Print PID holding bootstrap build lock on Linux)
 - rust-lang#107175 (Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`)
 - rust-lang#107204 (suggest qualifying bare associated constants)
 - rust-lang#107248 (abi: add AddressSpace field to Primitive::Pointer )
 - rust-lang#107272 (Implement ObjectSafe and WF in the new solver)
 - rust-lang#107285 (Implement `Generator` and `Future` in the new solver)
 - rust-lang#107286 (ICE in new solver if we see an inference variable)
 - rust-lang#107313 (Add Style Team Triagebot config)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5bc4980 into rust-lang:master Jan 26, 2023
@rustbot rustbot added this to the 1.69.0 milestone Jan 26, 2023
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Feb 9, 2023
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#106407 (Improve proc macro attribute diagnostics)
 - rust-lang#106960 (Teach parser to understand fake anonymous enum syntax)
 - rust-lang#107085 (Custom MIR: Support binary and unary operations)
 - rust-lang#107086 (Print PID holding bootstrap build lock on Linux)
 - rust-lang#107175 (Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`)
 - rust-lang#107204 (suggest qualifying bare associated constants)
 - rust-lang#107248 (abi: add AddressSpace field to Primitive::Pointer )
 - rust-lang#107272 (Implement ObjectSafe and WF in the new solver)
 - rust-lang#107285 (Implement `Generator` and `Future` in the new solver)
 - rust-lang#107286 (ICE in new solver if we see an inference variable)
 - rust-lang#107313 (Add Style Team Triagebot config)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@compiler-errors compiler-errors deleted the bad-types-in-vec-push branch August 11, 2023 19:55
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. 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.

[ICE]: index out of bounds: the len is 27 but the index is 28 snapshot_vec.rs
4 participants