forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#107175 - compiler-errors:bad-types-in-vec-p…
…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)
- Loading branch information
Showing
4 changed files
with
79 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// The error message here still is pretty confusing. | ||
|
||
fn main() { | ||
let mut result = vec![1]; | ||
// The type of `result` is constrained to be `Vec<{integer}>` here. | ||
// But the logic we use to find what expression constrains a type | ||
// is not sophisticated enough to know this. | ||
|
||
let mut vector = Vec::new(); | ||
vector.sort(); | ||
result.push(vector); | ||
//~^ ERROR mismatched types | ||
// So it thinks that the type of `result` is constrained here. | ||
} | ||
|
||
fn example2() { | ||
let mut x = vec![1]; | ||
x.push(""); | ||
//~^ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/bad-type-in-vec-push.rs:11:17 | ||
| | ||
LL | vector.sort(); | ||
| ------ here the type of `vector` is inferred to be `Vec<_>` | ||
LL | result.push(vector); | ||
| ---- ^^^^^^ expected integer, found struct `Vec` | ||
| | | ||
| arguments to this method are incorrect | ||
| | ||
= note: expected type `{integer}` | ||
found struct `Vec<_>` | ||
note: associated function defined here | ||
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/bad-type-in-vec-push.rs:18:12 | ||
| | ||
LL | x.push(""); | ||
| ---- ^^ expected integer, found `&str` | ||
| | | ||
| arguments to this method are incorrect | ||
| | ||
note: associated function defined here | ||
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |