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

Unclear "mismatched types" error #18154

Open
nyurik opened this issue Sep 19, 2024 · 3 comments
Open

Unclear "mismatched types" error #18154

nyurik opened this issue Sep 19, 2024 · 3 comments
Labels
C-bug Category: bug

Comments

@nyurik
Copy link
Contributor

nyurik commented Sep 19, 2024

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)

@nyurik nyurik added the C-bug Category: bug label Sep 19, 2024
@ChayimFriedman2
Copy link
Contributor

The diagnostics get emitted by rustc in JSON, we have no control over them (although r-a native diagnostics are even worse currently).

@nyurik
Copy link
Contributor Author

nyurik commented Sep 19, 2024

Makes sense, and rustc does make it clear because it uses comments on the code span itself - making it non-ambiguous. Does it make sense to show span info somewhere too in that error expansion? Or would it require rustc's message to be altered to make it clearer which type is which? Seems bad to loose span messages in r-a though...

@ChayimFriedman2
Copy link
Contributor

We don't lose spans, we split the diagnostic so each part is shown on its span.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants