Skip to content

"index out of bounds" with incorrect match #15883

Closed
@SludgePhD

Description

@SludgePhD

rust-analyzer version: 0.3.1722-standalone

rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)

relevant settings: none that should affect this

This code causes a panic inside rust-analyzer:

fn main() {
    match Some((true, false)) {
        Some(true) | Some(false) => {}
        None => {}
    }
}

Panic backtrace:

thread 'Worker' panicked at crates/hir-ty/src/diagnostics/match_check/usefulness.rs:371:18:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
   1: core::panicking::panic_fmt
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_bounds_check
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:162:5
   3: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
   4: hir_ty::diagnostics::match_check::deconstruct_pat::Constructor::split
   5: <core::iter::adapters::flatten::FlattenCompat<I,U> as core::iter::traits::iterator::Iterator>::next
   6: hir_ty::diagnostics::match_check::deconstruct_pat::SplitWildcard::split
   7: hir_ty::diagnostics::match_check::deconstruct_pat::Constructor::split
   8: hir_ty::diagnostics::match_check::usefulness::is_useful
   9: hir_ty::diagnostics::match_check::usefulness::is_useful
  10: hir_ty::diagnostics::match_check::usefulness::is_useful
  11: hir_ty::diagnostics::match_check::usefulness::compute_match_usefulness
  12: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect
  13: hir::DefWithBody::diagnostics
  14: hir::ModuleDef::diagnostics
  15: hir::Module::diagnostics
  16: ide_diagnostics::diagnostics
  17: std::panicking::try
  18: ide::Analysis::assists_with_fixes
  19: rust_analyzer::handlers::request::handle_code_action
  20: core::ops::function::FnOnce::call_once{{vtable.shim}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-patternpattern handling related thingsC-bugCategory: bugI-panic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions