Skip to content

Incorrect "mismatched types" message #121941

Closed

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 3, 2024
  2. veera-sivarajan commented on Mar 3, 2024

    @veera-sivarajan
    Contributor

    @rustbot claim

  3. added
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    on Mar 3, 2024
  4. added 2 commits that reference this issue on Mar 12, 2024
    fb5a579
    96b8225
  5. added 2 commits that reference this issue on Mar 13, 2024
    0dd4ffe
    5d13140
  6. added a commit that references this issue on Mar 13, 2024
    e7f72a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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