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

Incorrect "mismatched types" message #121941

Closed
pacak opened this issue Mar 3, 2024 · 1 comment · Fixed by #122360
Closed

Incorrect "mismatched types" message #121941

pacak opened this issue Mar 3, 2024 · 1 comment · Fixed by #122360
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pacak
Copy link
Contributor

pacak commented Mar 3, 2024

Code

fn atticus_megatron<T>(xs: &mut [T]) -> usize
where
    T: Copy + Eq,
{
    if xs.len > 2 {}
    0
}

Current output

error[E0615]: attempted to take value of method `len` on type `&mut [T]`
   --> lib.rs:294:11
    |
294 |     if xs.len > 2 {}
    |           ^^^ method, not a field
    |
help: use parentheses to call the method
    |
294 |     if xs.len() > 2 {}
    |              ++

error[E0308]: mismatched types
   --> lib.rs:294:17
    |
290 | fn atticus_megatron<T>(xs: &mut [T]) -> usize
    |                     - expected this type parameter
...
294 |     if xs.len > 2 {}
    |                 ^ expected type parameter `T`, found integer
    |
    = note: expected type parameter `T`
                         found type `{integer}`

Desired output

Second error message is wrong, rustc doesn't expect `T` and if you pass `T` - it won't work. Skip it?

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

or most recent nightly as of today

Anything else?

No response

@pacak pacak 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 Mar 3, 2024
@veera-sivarajan
Copy link
Contributor

@rustbot claim

@jieyouxu jieyouxu added the D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. label Mar 3, 2024
veera-sivarajan added a commit to veera-sivarajan/rust that referenced this issue Mar 12, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 13, 2024
…ompiler-errors

 Don't Create `ParamCandidate` When Obligation Contains Errors

Fixes rust-lang#121941

I'm not sure if I understand this correctly but this bug was caused by an error type incorrectly matching against `ParamCandidate`. This was introduced by the changes made in rust-lang#72621 (figured using cargo-bisect-rustc).

This PR fixes it by skipping `ParamCandidate` generation when an error type is involved. Also, this is similar to rust-lang#73005 but addresses `ParamCandidate` instead of `ImplCandidate`.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 13, 2024
…ompiler-errors

 Don't Create `ParamCandidate` When Obligation Contains Errors

Fixes rust-lang#121941

I'm not sure if I understand this correctly but this bug was caused by an error type incorrectly matching against `ParamCandidate`. This was introduced by the changes made in rust-lang#72621 (figured using cargo-bisect-rustc).

This PR fixes it by skipping `ParamCandidate` generation when an error type is involved. Also, this is similar to rust-lang#73005 but addresses `ParamCandidate` instead of `ImplCandidate`.
@bors bors closed this as completed in 96b8225 Mar 13, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 13, 2024
Rollup merge of rust-lang#122360 - veera-sivarajan:bugfix-121941, r=compiler-errors

 Don't Create `ParamCandidate` When Obligation Contains Errors

Fixes rust-lang#121941

I'm not sure if I understand this correctly but this bug was caused by an error type incorrectly matching against `ParamCandidate`. This was introduced by the changes made in rust-lang#72621 (figured using cargo-bisect-rustc).

This PR fixes it by skipping `ParamCandidate` generation when an error type is involved. Also, this is similar to rust-lang#73005 but addresses `ParamCandidate` instead of `ImplCandidate`.
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 D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants