Obtuse diagnostic: overflow evaluating the requirement `&_ well-formed`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic with the Rust code in the issue using the reported nightly version, then compare it with the branch-order variant and the desired E0308 output. The relevant examples reference src/main.rs, src/lib.rs, and alloc/src/vec/mod.rs; done means the original case reports the actionable type mismatch instead of overflowing on & _ well-formed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100