Skip to content

Rust analyser panicked in VSC #11659

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

Closed
martinellison opened this issue Mar 8, 2022 · 21 comments · Fixed by #11660
Closed

Rust analyser panicked in VSC #11659

martinellison opened this issue Mar 8, 2022 · 21 comments · Fixed by #11660
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@martinellison
Copy link

rust-analyzer version: 5fae65dd2 2022-03-07 stable

rustc version: rustc 1.61.0-nightly (03918badd 2022-03-07)

relevant settings:

VSC version

Version: 1.65.0
Commit: b5205cc8eb4fbaa726835538cd82372cc0222d43
Date: 2022-03-02T11:12:36.248Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.16.12-200.fc35.x86_64

Error dump as displayed

Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: textDocument/semanticTokens/full SemanticTokensParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/store.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::Local::ty
  53: ide::syntax_highlighting::highlight::highlight_def
  54: ide::syntax_highlighting::highlight::name_like
  55: ide::syntax_highlighting::highlight
  56: std::panicking::try
  57: rust_analyzer::handlers::handle_semantic_tokens_full
  58: std::panicking::try
  59: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/store.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for[Error - 18:23:18] Request textDocument/semanticTokens/full failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603 
 chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::source_analyzer::SourceAnalyzer::new_for_body
  53: hir::semantics::SemanticsImpl::analyze_impl
  54: ide::inlay_hints::inlay_hints
  55: std::panicking::try
  56: rust_analyzer::handlers::handle_inlay_hints
  57: std::panicking::try
  58: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::DefWithBody::diagnostics
  53: hir::Module::diagnostics
  54: ide_diagnostics::diagnostics
  55: std::panicking::try
  56: ide::Analysis::diagnostics
  57: rust_analyzer::handlers::publish_diagnostics
  58: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  59: alloc::vec::source_iter_marker::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
  60: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/store.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::source_analyzer::SourceAnalyzer::new_for_body
  53: hir::semantics::SemanticsImpl::analyze_impl
  54: ide::inlay_hints::inlay_hints
  55: std::panicking::try
  56: rust_analyzer::handlers::handle_inlay_hints
  57: std::panicking::try
  58: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/store.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::source_analyzer::SourceAnalyzer::new_for_body
  53: hir::semantics::SemanticsImpl::analyze_impl
  54: ide::inlay_hints::inlay_hints
  55: std::panicking::try
  56: rust_analyzer::handlers::handle_inlay_hints
  57: std::panicking::try
  58: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: textDocument/semanticTokens/range SemanticTokensRangeParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/store.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 23,
            character: 0,
        },
        end: Position {
            line: 207,
            character: 18,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::Local::ty
  53: ide::syntax_highlighting::highlight::highlight_def
  54: ide::syntax_highlighting::highlight::name_like
  55: ide::syntax_highlighting::highlight
  56: std::panicking::try
  57: rust_analyzer::handlers::handle_semantic_tokens_range
  58: std::panicking::try
  59: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 18:23:19] Request textDocument/semanticTokens/range failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603 
Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/store.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::source_analyzer::SourceAnalyzer::new_for_body
  53: hir::semantics::SemanticsImpl::analyze_impl
  54: ide::inlay_hints::inlay_hints
  55: std::panicking::try
  56: rust_analyzer::handlers::handle_inlay_hints
  57: std::panicking::try
  58: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 18:36:56] Request textDocument/hover failed.
  Message: Invalid offset
  Code: -32603 

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

Can you reproduce this easily (maybe by running rust-analyzer -v analysis-stats ., see https://rust-analyzer.github.io/manual.html#vs-code for the path to it)? Is your code public?

@martinellison
Copy link
Author

OK, what I get is the following, it seems to be the same error. I'll try agin in a minute with differeny code.

 ~/.vscode/extensions/matklad.rust-analyzer-0.2.964/server/rust-analyzer -v analysis-stats ../engine/src/lib.rs 
Database loaded:     1.06s, 220minstr (metadata 671.12ms, 29minstr; build 185.69ms, 9302kinstr)
  crates: 9, mods: 58, decls: 968, fns: 690
Item Collection:     12.24s, 69ginstr
0/690 0% processing: default (/home/martin/git/narthex-engine-trait/src/lib.rs 51/690 0% processing: default (/home/martin/git/narthex-engine-trait/src/lib.rs 52/690 0% processing: from_serial (/home/martin/git/narthex-engine-trait/src/lib.3/690 0% processing: default (/home/martin/git/narthex-engine-trait/src/lib.rs 74/690 0% processing: fmt (/home/martin/git/narthex-engine-trait/src/lib.rs 40..25/690 0% processing: fmt (/home/martin/git/narthex-engine-trait/src/lib.rs 41..26/690 0% processing: default (/home/martin/git/hypoboleus/codex-link/src/lib.rs 7/690 1% processing: into_iter (/home/martin/git/hypoboleus/codex-link/src/lib.rdefault (/home/martin/git/hypoboleus/codex-link/src/lib.rs 4527..4653)thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::method_resolution::iterate_trait_method_candidates
  31: hir_ty::method_resolution::iterate_method_candidates_dyn
  32: hir_ty::method_resolution::iterate_method_candidates
  33: hir_ty::infer::path::<impl hir_ty::infer::InferenceContext>::resolve_ty_assoc_item
  34: hir_ty::infer::path::<impl hir_ty::infer::InferenceContext>::infer_path
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  45: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  46: hir_ty::infer::infer_query
  47: salsa::runtime::Runtime::execute_query_implementation
  48: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  49: salsa::derived::slot::Slot<Q,MP>::read
  50: salsa::QueryTable<Q>::get
  51: <DB as hir_ty::db::HirDatabase>::infer_query
  52: hir_ty::db::infer_wait
  53: rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run
  54: rust_analyzer::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

CC #10390

@martinellison
Copy link
Author

yes, it is a duplicate, sorry.

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

It's fine, it may or may not be the same issue, and yours might be easier to minimize. A small test case would be lovely.

@martinellison
Copy link
Author

I've tried some other code that is on github, but rust analyser is working with it. I'll look further.

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

There's no easy way to minimize these, but you can start from the function that's shown last in analysis-stats (you might want to make the terminal wider, though). In general, code doesn't need to compile for RA to work, so you can try trimming whole modules at first.

@martinellison
Copy link
Author

Here's a relatively short module that exhibits the panic. I have pulled it out of a much larger program, so I don't know if it will fail properly on its own.

Some code

//! code for [WorldData]
use getset::Getters;

use crate::{
    item::entry_list::item_entry_list::ItemEntryList, search::Search, ItemLink, Result,
    SearchCriterion,
};
// --- WorldData ---
/** An `WorldData`  is data for rendering that is not specific to individual
items. */
#[derive(Debug, Default, Getters)]
pub struct WorldData {
    #[getset(get = "pub")]
    possible_parents: ItemEntryList,
    #[getset(get = "pub")]
    possible_contexts: ItemEntryList,
    #[getset(get = "pub")]
    open_tasks: ItemEntryList,
    #[getset(get = "pub")]
    last_search_criterion: Option<SearchCriterion>,
    #[getset(get = "pub")]
    inbox_context: Option<ItemLink>,
}
impl super::World {
    /** `world_data` returns the [WorldData] */
    pub fn world_data(&self) -> Result<Box<WorldData>> {
        Ok(Box::new(WorldData {
            possible_parents: ItemEntryList::from(self.possible_parents()?),
            possible_contexts: ItemEntryList::from(self.possible_contexts()?),
            open_tasks: Search::search(self, &SearchCriterion::open_task_criterion())?,
            last_search_criterion: self.last_search_criterion.clone(),
            inbox_context: self.inbox_context.clone(),
        }))
    }
}

Dump

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::DefWithBody::diagnostics
  53: hir::Module::diagnostics
  54: ide_diagnostics::diagnostics
  55: std::panicking::try
  56: ide::Analysis::diagnostics
  57: rust_analyzer::handlers::publish_diagnostics
  58: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  59: alloc::vec::source_iter_marker::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
  60: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   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::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::struct_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::struct_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::infer::unify::InferenceTable::try_obligation
  31: hir_ty::autoderef::autoderef_step
  32: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  33: hir_ty::method_resolution::autoderef_method_receiver
  34: hir_ty::method_resolution::iterate_method_candidates_dyn
  35: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  36: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  37: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  38: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  39: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  43: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  44: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  45: hir_ty::infer::infer_query
  46: salsa::runtime::Runtime::execute_query_implementation
  47: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  48: salsa::derived::slot::Slot<Q,MP>::read
  49: salsa::QueryTable<Q>::get
  50: <DB as hir_ty::db::HirDatabase>::infer_query
  51: hir_ty::db::infer_wait
  52: hir::DefWithBody::diagnostics
  53: hir::Module::diagnostics
  54: ide_diagnostics::diagnostics
  55: std::panicking::try
  56: ide::Analysis::diagnostics
  57: rust_analyzer::handlers::publish_diagnostics
  58: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  59: alloc::vec::source_iter_marker::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
  60: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 5fae65dd2 2022-03-07 stable
request: textDocument/codeAction CodeActionParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/martin/git/hypoboleus/engine/src/world/worlddata.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 34,
            character: 1,
        },
    },
    context: CodeActionContext {
        diagnostics: [],
        only: None,
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::Binders<T>::substitute
   6: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   7: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   8: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   9: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  10: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  11: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  12: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  13: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  14: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  15: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  16: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  17: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  18: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
  19: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  20: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  21: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  22: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  23: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  24: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  25: hir_ty::infer::infer_query
  26: salsa::runtime::Runtime::execute_query_implementation
  27: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  28: salsa::derived::slot::Slot<Q,MP>::read
  29: salsa::QueryTable<Q>::get
  30: <DB as hir_ty::db::HirDatabase>::infer_query
  31: hir_ty::db::infer_wait
  32: hir::source_analyzer::SourceAnalyzer::new_for_body
  33: hir::semantics::SemanticsImpl::analyze_impl
  34: ide_db::defs::NameRefClass::classify
  35: ide_db::search::FindUsages::found_name_ref
  36: ide_db::search::FindUsages::search
  37: ide_db::search::FindUsages::all
  38: ide_assists::handlers::extract_module::Module::expand_and_group_usages_file_wise
  39: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  40: ide_assists::handlers::extract_module::extract_module
  41: ide_assists::assists
  42: std::panicking::try
  43: rust_analyzer::handlers::handle_code_action
  44: std::panicking::try
  45: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

That's a start, but I don't think it works asa reproduction. I would try to drop the proc macro (accessing the fields directly should work, if the getters don't do anything fancy) and include the structs that are used by the code. You might also be able to remove some of the fields, probably one is enough to trigger the crash.

@martinellison
Copy link
Author

When I take the file out and copy it into a single-file crate, I do not get the panic in the small crate.

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

I think you dropped the -v in the last couple of runs. It's useful because it lets you check that the crash is really happening on the function you're looking at.

@martinellison
Copy link
Author

The following does crash as a stand-alone; I'll see if I can shorten it.

#![feature(backtrace, backtrace_frames, try_blocks)]
//#![warn(missing_docs)] suppressed too many messages
/// trace macro for debugging the code in this file
macro_rules! main_trace {
    () => { log::trace!() };
    ($($arg:tt)*) => {
        log::trace!("{} ({}:{})", RGB(0, 235, 215).on(Purple).paint(format!($($arg)*)), std::file!(), std::line!())
    };
}
mod ident;
mod link_base;
mod link_store;
mod linkable;
mod linkbaseserde;
mod linkitem;
mod linkitemserde;
mod linkset;
mod multi;
mod single;
/** `codex_link` supports links between objects.

This crate is used to provide one-to-many and many-to-many links between
objects. Provide an enum `LinkType` which lists the various kinds of link.

Note: the links are implemented by *weak* links. Provide at least one *strong*
link (`LinkableLink`) to each [Linkable] so they are not dropped, for example by
using a [LinkStore] to contain them. */
use std::{
    backtrace::Backtrace,
    cell::RefCell,
    fmt::{Debug, Display, Formatter},
    rc::Rc,
};

//use arr_macro::arr;
use array_init::array_init;
use getset::Getters;
pub use ident::Ident;
pub use linkable::Linkable;
use linkbaseserde::LinkBaseSerde;
use linkitemserde::LinkItemSerde;
use serde::{Deserialize, Serialize};
use thiserror::Error;
extern crate enum_primitive;
use std::{
    iter::Iterator,
    ops::{Index, IndexMut},
};
mod weak_link;
use delegate_attr::delegate;
pub use link_store::LinkStore;
pub use weak_link::LinkableWeakLink;

use crate::link_base::LinkBase;
//use strum::IntoEnumIterator;
//use color_eyre::eyre::Result;
#[cfg(test)]
mod tests;
#[derive(Error, Debug)]
/** errors generated by this crate */
pub enum LinkError {
    #[error("weak link to nowhere")]
    BadWeakLink,
    #[error("link unresolved")]
    UnresolvedLink,
    #[error("ident {0} not found")]
    IdentNotFound(String),
    #[error("deserialize error")]
    SerdeError(#[from] ron::error::Error),
    #[error("cannot upgrade")]
    CannotUpgrade,
    #[error("cannot convert {0} to link type")]
    BadLinkType(usize),
    #[error("link already borrowed")]
    LinkAlreadyBorrowed,
    #[error("internal error: {}", .0)]
    Internal(String),
    #[error("other {:#?}", .backtrace.frames())]
    Other {
        #[from]
        source: eyre::Error,
        backtrace: Backtrace,
    },
}
// --- LinkData ---
/** the data to be linked */
pub trait LinkData<const LINKSIZE: usize>
where
    Self: Clone
        + Serialize
        + for<'a> Deserialize<'a>
        + Default
        + Debug
        + Display
        + From<Self::Serde>
        + Clone
        + Debug
        + Display
        + Serialize
        + for<'a> Deserialize<'a>
        + Default,
    Self::LinkType: Eq
        + PartialEq
        + Ord
        + PartialOrd
        + Copy
        + Debug
        + PartialEq
        + Clone
        + Copy
        + Eq
        + PartialOrd
        + Ord
        + Debug
        + Display
        + Serialize
        + for<'a> Deserialize<'a>
        + Default
        + From<usize>
        + Into<usize>,
    Self::Serde:
        for<'a> Deserialize<'a> + Debug + Serialize + for<'a> Deserialize<'a> + From<Self> + Clone,
{
    type LinkType;
    type Serde;
}
/** results  generated by this crate */
pub type Result<T> = std::result::Result<T, LinkError>;
// --- LinkSerdeOption ---
/** optional [Ident], used for serialising optional [LinkableWeakLink] */
#[derive(Clone, Serialize, Deserialize, Default, Debug)]
pub(crate) struct LinkSerdeOption {
    #[serde(skip_serializing_if = "Option::is_none", default)]
    li: Option<Ident>,
}
// --- LinkSerdeVector ---
/** An `LinkSerdeVector` vector of LinkSerdeOption */
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(transparent)]
pub(crate) struct LinkSerdeVector<LT>(Vec<LinkItemSerde<LT>>);
#[delegate(self.0)]
impl<LT> LinkSerdeVector<LT> {
    fn is_empty(&self) -> bool;

    fn iter(&self) -> impl Iterator<Item = &LinkItemSerde<LT>>;
}
impl<LT> Default for LinkSerdeVector<LT> {
    fn default() -> Self { Self(vec![]) }
}
/** An iterator over LinkSerdeVector */
impl<LT> IntoIterator for LinkSerdeVector<LT> {
    type IntoIter = std::vec::IntoIter<Self::Item>;
    type Item = LinkItemSerde<LT>;

    fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
}
// --- LinkArray ---
/** An `LinkArray` fixed-sized array of Link options */
#[derive(Clone)]
pub(crate) struct LinkArray<const N: usize, LD: LinkData<N>>([LinkableWeakLinkOption<N, LD>; N]);
impl<const N: usize, LD: LinkData<N>> Default for LinkArray<N, LD> {
    fn default() -> Self {
        let defarray = array_init(|_i| LinkableWeakLinkOption::default());
        Self(defarray)
    }
}
impl<const N: usize, LD: LinkData<N>> Index<LD::LinkType> for LinkArray<N, LD> {
    type Output = LinkableWeakLinkOption<N, LD>;

    fn index(&self, link_type: LD::LinkType) -> &Self::Output { self.0.index(link_type.into()) }
}
impl<const N: usize, LD: LinkData<N>> IndexMut<LD::LinkType> for LinkArray<N, LD> {
    fn index_mut(&mut self, link_type: LD::LinkType) -> &mut Self::Output {
        self.0.index_mut(link_type.into())
    }
}
impl<const N: usize, LD: LinkData<N>> Debug for LinkArray<N, LD> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        for i in 0..N {
            write!(f, "{}: {:?}", LD::LinkType::from(i), self.0[i])?;
            if i != N - 1 {
                write!(f, ", ")?;
            }
        }
        Ok(())
    }
}
// --- LinkableSerde ---
#[derive(Getters, Serialize, Default, Debug, Deserialize)]
/** for (de)serialising [Linkable] */
pub struct LinkableSerde<const N: usize, LD>
where
    LD: LinkData<N>,
{
    #[serde(rename = "d")]
    #[getset(get = "pub")]
    data: LD::Serde,
    #[serde(rename = "l")]
    links: LinkBaseSerde<N, LD::LinkType>,
}
impl<const N: usize, LD: LinkData<N>> From<Linkable<N, LD>> for LinkableSerde<N, LD> {
    fn from(l: Linkable<N, LD>) -> Self {
        Self {
            data: l.data.into(),
            links: l.links.into(),
        }
    }
}
impl<const N: usize, LD: LinkData<N>> LinkableSerde<N, LD> {
    /** `deserialize_to` deserialises a [Linkable], updates the [LinkStore]
     * and returns a [LinkableWeakLink] */
    pub fn deserialize_to<F>(
        data: &str,
        link_store: &mut LinkStore<N, LD>,
        is_selected: F,
    ) -> Result<Option<LinkableWeakLink<N, LD>>>
    where
        F: Fn(&LinkableSerde<N, LD>) -> bool,
    {
        let linkable_serde: Self = ron::de::from_str(data)?;
        if !is_selected(&linkable_serde) {
            return Ok(None);
        }
        let ident = linkable_serde.links.ident();
        let mut weak_link = link_store.ensure(ident, Linkable::<N, LD>::new)?;
        weak_link.deserialize_from(&linkable_serde, link_store)?;
        Ok(Some(weak_link))
    }
}
// --- LinkableLink ---
/** strong link between [Linkable]s */
#[derive(Clone)]
struct LinkableLink<const N: usize, LD: LinkData<N>>(Rc<RefCell<Linkable<N, LD>>>);
impl<const N: usize, LD: LinkData<N>> Debug for LinkableLink<N, LD> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "->{}", self.0.as_ref().borrow())
    }
}
impl<const N: usize, LD: LinkData<N>> Display for LinkableLink<N, LD> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, ":>{:?}", self.0.as_ref().borrow())
    }
}
#[delegate(self.0.as_ref().borrow())]
impl<const N: usize, LD: LinkData<N>> LinkableLink<N, LD> {
    fn ident(&self) -> Ident;
}
impl<const N: usize, LD: LinkData<N>> LinkableLink<N, LD> {
    fn new(l: Linkable<N, LD>) -> Self { Self(Rc::new(RefCell::new(l))) }

    fn downgrade(&self) -> LinkableWeakLink<N, LD> {
        LinkableWeakLink::<N, LD>::new(Rc::downgrade(&self.0))
    }
}
// --- LinkableWeakLinkOption ---
/** an option of a [LinkableWeakLink] */

#[derive(Clone)]
pub struct LinkableWeakLinkOption<const N: usize, LD: LinkData<N>>(Option<LinkableWeakLink<N, LD>>);
//use std::fmt::{Debug, Display, Formatter};
impl<const N: usize, LD: LinkData<N>> Debug for LinkableWeakLinkOption<N, LD> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if let Some(wl) = &self.0 {
            write!(f, "@{:?}", &wl)
        } else {
            write!(f, "(none)")
        }
    }
}
#[delegate(self.0)]
impl<const N: usize, LD: LinkData<N>> LinkableWeakLinkOption<N, LD> {
    fn ok_or_else<E, F>(self, err: F) -> std::result::Result<LinkableWeakLink<N, LD>, E>
    where
        F: FnOnce() -> E;

    fn is_none(&self) -> bool;

    fn is_some(&self) -> bool;
}
impl<const N: usize, LD: LinkData<N>> Default for LinkableWeakLinkOption<N, LD> {
    fn default() -> Self { Self(None) }
}
impl<const N: usize, LD: LinkData<N>> From<LinkableWeakLink<N, LD>>
    for LinkableWeakLinkOption<N, LD>
{
    fn from(link: LinkableWeakLink<N, LD>) -> Self { Self(Some(link)) }
}
impl<const N: usize, LD: LinkData<N>> From<Option<LinkableWeakLink<N, LD>>>
    for LinkableWeakLinkOption<N, LD>
{
    fn from(link_option: Option<LinkableWeakLink<N, LD>>) -> Self { Self(link_option) }
}
impl<const N: usize, LD: LinkData<N>> From<LinkableWeakLinkOption<N, LD>>
    for Option<LinkableWeakLink<N, LD>>
{
    fn from(link_option: LinkableWeakLinkOption<N, LD>) -> Option<LinkableWeakLink<N, LD>> {
        link_option.0
    }
}
impl<const N: usize, LD: LinkData<N>> LinkableWeakLinkOption<N, LD> {
    pub fn inner(self) -> Option<LinkableWeakLink<N, LD>> { self.0 }
}

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

Slightly minimized:

struct LinkArray<const N: usize, LD>(LD);
fn f<const N: usize, LD>(x: LD) -> LinkArray<N, LD> {
    LinkArray::<N, LD>(x)
}

@lnicola lnicola added A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now labels Mar 8, 2022
@martinellison
Copy link
Author

Yes, can confirm.

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

Regressed by #11140, CC @HKalbasi

@martinellison
Copy link
Author

Does this mean we have to put the type parameters first and then the constants (in generics)? Is my code wrong? Or is this a rust analyser issue?

@lnicola
Copy link
Member

lnicola commented Mar 8, 2022

It looks like reordering the arguments makes it work:

struct LinkArray<LD, const N: usize>(LD);
fn f<LD, const N: usize>(x: LD) -> LinkArray<LD, N> {
    LinkArray::<LD, N>(x)
}

But (assuming out minimization has the same cause as your original crash) your code is correct. This was caused by a recent PR which made RA accept the generic arguments in any order.

@the10thWiz
Copy link

the10thWiz commented Mar 9, 2022

I think I may have found a related crash. Specifically the following code causes the server to crash:

pub struct Vec2;
pub struct CurvePoint;
pub struct Mesh;
pub fn gen_curve<const N: usize>(curve: impl Iterator<Item = CurvePoint>, offsets: [Vec2; N],) -> Mesh {
    todo!()
}

pub fn gen(curve: impl Iterator<Item = CurvePoint>) -> Mesh {
    gen_curve(curve, [Vec2, Vec2, Vec2, Vec2])
}

My best guess is that the server crashes due to placing the Type Generic after the Const Generic (as above), but it may be harder to see, since the type generic is actually created by the impl Iterator parameter. This means that unlike the previous example, the code actually compiles.

EDIT:
I've tested #11660, and it does also fix the crash for this example.

@bors bors bot closed this as completed in 4fcaefa Mar 9, 2022
@martinellison
Copy link
Author

works for me now thanks.

@rkuhn
Copy link

rkuhn commented Mar 10, 2022

wow, you guys are amazing — I was just wondering how to minimise and report and then I found this and tonight’s build fixes the issue

@lnicola
Copy link
Member

lnicola commented Mar 10, 2022

@rkuhn http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/ is a very good for test case minimization, but in RA you can generally play it fast and loose because it works with code that doesn't compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants