Skip to content

Incorrect "mismatched types" message #121941

Closed
@pacak

Description

@pacak

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

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions