Skip to content

Assosiated const str in match cause panic #20149

Open
@Dushistov

Description

@Dushistov

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer 0.0.0 (11d45c8 2025-07-02)

rustc version: (eg. output of rustc -V)

rustc 1.88.0 (6b00bc388 2025-06-23)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)

GNU Emacs 30.1 (lsp-mode)

code snippet to reproduce:

trait Foo {
    const C: &str;
}

impl Foo for i32 {
    const C: &str = "i32";
}

impl Foo for i64 {
    const C: &str = "i64";
}

fn main() {
    let s = "i64";
    match s {
        i32::C => println!("this is i32"),
        i64::C => println!("this is i64"),
        _ => println!("unknown"),
    }
}

on my machine this cause panic:

thread 'Worker0' panicked at crates/hir-ty/src/mir.rs:183:21:
internal error: entered unreachable code: Overloaded deref on type str is not a projection
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: hir_ty::mir::ProjectionElem<V,T>::projected_ty
   3: hir_ty::mir::borrowck::moved_out_of_ref::{{closure}}
   4: hir_ty::mir::borrowck::borrowck_query::{{closure}}
   5: hir_ty::mir::borrowck::borrowck_query
   6: salsa::function::execute::<impl salsa::function::IngredientImpl<C>>::execute
   7: salsa::function::fetch::<impl salsa::function::IngredientImpl<C>>::fetch_cold_with_retry
   8: salsa::function::fetch::<impl salsa::function::IngredientImpl<C>>::fetch
   9: std::thread::local::LocalKey<T>::with
  10: <DB as hir_ty::db::HirDatabase>::borrowck::borrowck_shim
  11: hir::DefWithBody::diagnostics
  12: hir::ModuleDef::diagnostics
  13: hir::Module::diagnostics
  14: ide_diagnostics::semantic_diagnostics
  15: ide_diagnostics::full_diagnostics
  16: salsa::cancelled::Cancelled::catch
  17: ide::Analysis::assists_with_fixes
  18: rust_analyzer::handlers::request::handle_code_action
  19: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stacktrace:
   0: borrowck_shim(Id(1c1f0)) -> (R26, Durability::MEDIUM)
             at crates/hir-ty/src/db.rs:31

additional context:
   0: 
version: 0.0.0 (11d45c8813 2025-07-02)
request: textDocument/codeAction CodeActionParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/Users/evgeniy/.emacs.d/rust-playground/at-2025-07-02-192510/src/main.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 22,
            character: 18,
        },
        end: Position {
            line: 22,
            character: 18,
        },
    },
    context: CodeActionContext {
        diagnostics: [],
        only: None,
        trigger_kind: None,
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

seems similar to #19500 , but backtrace is not exactly equal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions