Skip to content

thread 'Worker' panicked at 'index out of bounds: the len is 0 but the index is 0', chalk-ir-0.89.0\src\fold\subst.rs:55:19 #14966

Closed
@frozenlib

Description

@frozenlib

The following code will cause rust-analyzer to panic.

How to reproduce

  1. Create a new crate with cargo init --lib.
  2. Paste the following code into lib.rs.
  3. Click on the beginning of the file and move the cursor there.
trait A<T> {
    fn a(&self);
}
struct B;
impl B {
    pub fn b<T>(s: &dyn A<T>) -> Self {
        B
    }
}
struct C;
impl C {
    fn c<T>(a: &dyn A<T>) -> Self {
        let mut c = C;
        let b = B::b(a);
        c.d(|| a.a());
        c
    }
    fn d(&mut self, f: impl FnOnce()) {}
}

rust-analyzer version: rust-analyzer version: 0.3.1533-standalone (505fd09 2023-05-28)
rustc version: rustc 1.70.0 (90c541806 2023-05-31)
relevant settings: Use default settings

Output:

Output :
Panic context:
> 
version: 0.3.1533-standalone (505fd09f9 2023-05-28)
request: textDocument/codeAction CodeActionParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/z%3A/crash_example/src/lib.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 0,
            character: 0,
        },
    },
    context: CodeActionContext {
        diagnostics: [],
        only: None,
        trigger_kind: Some(
            Automatic,
        ),
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

thread 'Worker' panicked at 'index out of bounds: the len is 0 but the index is 0', C:\Users\runneradmin\.cargo\registry\src\mygithub.libinneed.workers.dev-1ecc6299db9ec823\chalk-ir-0.89.0\src\fold\subst.rs:55:19
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library\std\src\panicking.rs:579
   1: core::panicking::panic_fmt
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library\core\src\panicking.rs:64
   2: core::panicking::panic_bounds_check
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library\core\src\panicking.rs:159
   3: chalk_ir::visit::TypeVisitor::visit_ty
   4: chalk_ir::fold::TypeSuperFoldable::super_fold_with
   5: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next
   6: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
   7: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::try_fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::WhereClause<I>>::try_fold_with
   9: chalk_solve::infer::instantiate::<impl chalk_solve::infer::InferenceTable<I>>::instantiate_binders_universally
  10: <chalk_solve::infer::unify::Unifier<I> as chalk_ir::zip::Zipper<I>>::zip_binders
  11: <chalk_solve::infer::unify::Unifier<I> as chalk_ir::zip::Zipper<I>>::zip_binders
  12: chalk_solve::infer::unify::Unifier<I>::relate_ty_ty
  13: <chalk_solve::infer::unify::Unifier<I> as chalk_ir::zip::Zipper<I>>::zip_tys
  14: chalk_solve::infer::unify::Unifier<I>::relate_ty_ty
  15: chalk_solve::infer::unify::Unifier<I>::generalize_ty
  16: chalk_solve::infer::unify::Unifier<I>::relate_ty_ty
  17: <chalk_solve::infer::unify::Unifier<I> as chalk_ir::zip::Zipper<I>>::zip_tys
  18: chalk_ir::zip::Zipper::zip_substs
  19: chalk_ir::_::<impl chalk_ir::zip::Zip<I> for chalk_ir::WhereClause<I>>::zip_with
  20: chalk_ir::_::<impl chalk_ir::zip::Zip<I> for chalk_ir::DomainGoal<I>>::zip_with
  21: chalk_solve::infer::unify::Unifier<I>::relate
  22: chalk_recursive::fulfill::Fulfill<I,Solver>::new_with_clause
  23: chalk_recursive::solve::SolveIteration::solve_iteration
  24: chalk_recursive::solve::SolveIteration::solve_iteration
  25: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  26: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  27: hir_ty::traits::trait_solve_query
  28: salsa::runtime::Runtime::execute_query_implementation
  29: core::ptr::drop_in_place<salsa::derived::slot::QueryState<hir_ty::db::ConstEvalDiscriminantQuery>>
  30: salsa::derived::slot::Slot<Q,MP>::read
  31: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  32: salsa::QueryTable<Q>::get
  33: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  34: hir_ty::db::trait_solve_wait
  35: <DB as hir_ty::db::HirDatabase>::trait_solve
  36: <chalk_ir::Ty<hir_ty::interner::Interner> as hir_ty::chalk_ext::TyExt>::is_copy
  37: hir_ty::mir::lower::MirLowerCtx::push_storage_live_for_local
  38: hir_ty::mir::lower::MirLowerCtx::push_storage_live_for_local
  39: hir_ty::mir::lower::MirLowerCtx::lower_expr_to_some_operand
  40: hir_ty::mir::lower::MirLowerCtx::lower_expr_to_some_operand
  41: hir_ty::mir::lower::MirLowerCtx::lower_expr_to_some_operand
  42: hir_ty::mir::lower::lower_to_mir
  43: hir_ty::mir::lower::mir_body_query
  44: salsa::runtime::Runtime::execute_query_implementation
  45: core::ptr::drop_in_place<salsa::derived::slot::QueryState<hir_ty::db::ConstEvalDiscriminantQuery>>
  46: salsa::derived::slot::Slot<Q,MP>::read
  47: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  48: <DB as hir_ty::db::HirDatabase>::mir_body
  49: hir_ty::mir::borrowck::borrowck_query
  50: salsa::runtime::Runtime::execute_query_implementation
  51: core::ptr::drop_in_place<salsa::derived::slot::QueryState<hir_ty::db::ConstEvalDiscriminantQuery>>
  52: salsa::derived::slot::Slot<Q,MP>::read
  53: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  54: <DB as hir_ty::db::HirDatabase>::borrowck
  55: hir::DefWithBody::diagnostics
  56: hir::Module::diagnostics
  57: ide_diagnostics::diagnostics
  58: std::panicking::try
  59: rust_analyzer::handlers::request::handle_code_action
  60: std::panicking::try
  61: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugI-panic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions