rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.39k stars 1.62k forks source link

Request textDocument/inlayHint failed #18613

Open artemexex3000 opened 9 hours ago

artemexex3000 commented 9 hours ago

rust-analyzer version: rust-analyzer 1.82.0 (f6e511e 2024-10-15)

rustc version: rustc 1.82.0 (f6e511eec 2024-10-15)

editor or extension: vscode (code -v: 1.92.0 b1c0a14de1414fcdaa400695b4db1c0799bc3124 x64)

relevant settings:

"rust-analyzer.inlayHints.lifetimeElisionHints.enable" = "always";
"rust-analyzer.inlayHints.lifetimeElisionHints.useParameterNames" = true;
"rust-analyzer.inlayHints.closureCaptureHints.enable" = true;

code snippet to reproduce:

fn main() {
    let box_value = Box::<String>new();
}
Panic context:
> 
version: 0.3.2204-standalone
request: textDocument/inlayHint InlayHintParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/artemexex3000/VSCode/sandbox/socket_sender/src/main.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 16,
            character: 0,
        },
    },
}

thread 'Worker' panicked at crates/hir-ty/src/display.rs:1055:69:
mid > len
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <chalk_ir::Ty<hir_ty::interner::Interner> as hir_ty::display::HirDisplay>::hir_fmt
   3: hir_ty::display::HirDisplayWrapper<T>::write_to
   4: ide::inlay_hints::label_of_ty::rec
   5: ide::inlay_hints::label_of_ty
   6: ide::inlay_hints::bind_pat::hints
   7: ide::inlay_hints::hints
   8: ide::inlay_hints::inlay_hints
   9: ra_salsa::Cancelled::catch
  10: rust_analyzer::handlers::request::handle_inlay_hints
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 4:29:03 PM] Request textDocument/inlayHint failed.
  Message: request handler panicked: mid > len
  Code: -32603 
Veykril commented 9 hours ago

Panic triggers here https://github.com/rust-lang/rust-analyzer/blob/65c0b297204fcce1096ed6d6fe3f0f224563dbb8/crates/hir-ty/src/display.rs#L1055

minimal reproduction

fn main() {
    struct S<T, D = ()>();
    let x = S::<()>;}

The issue is our index for split_at assumes all parameters, but at that point they are stripped of the defaults so the index might not be valid