]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #107175 - compiler-errors:bad-types-in-vec-push, r=estebank
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 26 Jan 2023 05:15:26 +0000 (06:15 +0100)
committerGitHub <noreply@github.com>
Thu, 26 Jan 2023 05:15:26 +0000 (06:15 +0100)
commit5bc49807ddad3669836e3bbfe09ab680bc6aad3d
tree10501d27b4b439ca992db6e96f9cc20fdbb0c8ee
parent4b51b20d8710f7e543be02ac9ef6f65842c1926a
parent9f933b5642c08e4241cbfed0f15270df552ce8e6
Rollup merge of #107175 - compiler-errors:bad-types-in-vec-push, r=estebank

Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`

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:

```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 #106590, but that's a bit bigger issue that needs some more thinking about)
compiler/rustc_hir_typeck/src/demand.rs
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs