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

Obtuse diagnostic: overflow evaluating the requirement &_ well-formed #128397

Open
meithecatte opened this issue Jul 30, 2024 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@meithecatte
Copy link
Contributor

meithecatte commented Jul 30, 2024

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

@meithecatte meithecatte added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2024
@compiler-errors
Copy link
Member

This is another fallout from removing sub_relations, cc @lcnr #119989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants