Skip to content

Unclear "mismatched types" error #18154

Open
@nyurik

Description

@nyurik

As seen in this image, the inline error message is very unclear: which type do I use, vs which type I should be using instead. It simply lists two types and their source files. It requires full dialog to be open to understand which is which.

Image

error[E0308]: mismatched types
   --> clippy_lints/src/functions/ref_option.rs:18:40
    |
18  |         if is_type_diagnostic_item(cx, *ty, sym::Option)
    |            -----------------------     ^^^ expected `rustc_middle::ty::Ty<'_>`, found `rustc_hir::Ty<'_>`
    |            |
    |            arguments to this function are incorrect
    |
    = note: `rustc_hir::Ty<'_>` and `rustc_middle::ty::Ty<'_>` have similar names, but are actually distinct types
note: `rustc_hir::Ty<'_>` is defined in crate `rustc_hir`
   --> /home/nyurik/.rustup/toolchains/nightly-2024-09-05-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/compiler/rustc_hir/src/hir.rs:2539:1
note: `rustc_middle::ty::Ty<'_>` is defined in crate `rustc_middle`
   --> /home/nyurik/.rustup/toolchains/nightly-2024-09-05-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/compiler/rustc_middle/src/ty/mod.rs:440:1
note: function defined here
   --> /home/nyurik/dev/rust/rust-clippy/clippy_utils/src/ty.rs:445:8
    |
445 | pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool {
    |        ^^^^^^^^^^^^^^^^^^^^^^^

rust-analyzer version: rust-analyzer version: 0.3.2112-standalone

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: vscode, ext 0.3.2112

relevant settings: defaults

repository link (if public, optional): (eg. rust-analyzer)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions