Open
Description
Code
fn main() {
let v = vec![];
loop {
if todo!() {
let x = v.last().unwrap();
v.push(x); // NOTE: should be v.push(*x);
} else {
v.push(0);
}
}
}
Current output
error[E0275]: overflow evaluating the requirement `&_ well-formed`
--> src/main.rs:5:21
|
5 | let x = v.last().unwrap();
| ^^^^^^^^
Desired output
error[E0308]: mismatched types
--> src/lib.rs:6:20
|
6 | v.push(x); // NOTE: should be v.push(*x);
| ---- ^ expected `{?T}`, found `&{?T}`
| |
| arguments to this method are incorrect
|
note: method defined here
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:1994:12
|
1994 | pub fn push(&mut self, value: T) {
| ^^^^
help: consider dereferencing the borrow
|
6 | v.push(*x); // NOTE: should be v.push(*x);
| +
Rationale and extra context
The current error message uses jargon that is probably only understandable by compiler developers, type theory enthusiasts, and possibly some genders of Haskell junkies – in an area of the language very easily encountered by newcomers.
Other cases
Swapping the order of the branches yields very good output:
error[E0308]: mismatched types
--> src/lib.rs:8:20
|
5 | v.push(0);
| - - this argument has type `{integer}`...
| |
| ... which causes `v` to have type `Vec<{integer}>`
...
8 | v.push(x);
| ---- ^ expected integer, found `&{integer}`
| |
| arguments to this method are incorrect
|
note: method defined here
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:1994:12
|
1994 | pub fn push(&mut self, value: T) {
| ^^^^
Rust Version
rustc 1.82.0-nightly (92c6c0380 2024-07-21)
binary: rustc
commit-hash: 92c6c03805408a1a261b98013304e9bbf59ee428
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7
Anything else?
No response