rust-lang / rust-analyzer

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

thread '<unnamed>' panicked at 'Internal error, cycle detected #8824

Closed davidlattimore closed 3 years ago

davidlattimore commented 3 years ago

With rustup default beta

Cargo.toml:

[package]
name = "foo"
version = "1.0.0"
edition = "2018"

[dependencies]

and the following lib.rs

fn foo() {
    let mut xs: Vec<u8> = Vec::new();
}

Then running rust-analyzer diagnostics ., I get the following panic:

thread '<unnamed>' panicked at 'Internal error, cycle detected:

DatabaseKeyIndex { group_index: 7, query_index: 10, key_index: 370 }
DatabaseKeyIndex { group_index: 7, query_index: 8, key_index: 45 }
', /home/d/.cargo/registry/src/github.com-1ecc6299db9ec823/salsa-0.16.0/src/lib.rs:490:48
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:435:5
   2: salsa::QueryTable<Q>::get::{{closure}}
   3: <DB as hir_ty::db::HirDatabase>::generic_defaults::__shim
   4: <DB as hir_ty::db::HirDatabase>::generic_defaults
   5: hir_ty::lower::substs_from_path_segment
   6: hir_ty::lower::<impl hir_ty::TraitRef>::from_resolved_path
   7: hir_ty::lower::<impl hir_ty::TraitRef>::from_path
   8: hir_ty::lower::<impl hir_ty::GenericPredicate>::from_type_bound
   9: hir_ty::lower::<impl hir_ty::GenericPredicate>::from_where_predicate
  10: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  11: <alloc::vec::Vec<T> as alloc::vec::SpecFromIter<T,I>>::from_iter
  12: hir_ty::lower::generic_predicates_for_param_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::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  17: <DB as hir_ty::db::HirDatabase>::generic_predicates_for_param::__shim
  18: <DB as hir_ty::db::HirDatabase>::generic_predicates_for_param
  19: hir_ty::utils::all_super_trait_refs
  20: hir_ty::utils::associated_type_by_name_including_super_traits
  21: hir_ty::lower::<impl hir_ty::Ty>::from_partly_resolved_hir_path
  22: hir_ty::lower::<impl hir_ty::Ty>::from_hir_ext
  23: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  24: <alloc::vec::Vec<T> as alloc::vec::SpecFromIter<T,I>>::from_iter
  25: hir_ty::lower::generic_defaults_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::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  30: <DB as hir_ty::db::HirDatabase>::generic_defaults::__shim
  31: <DB as hir_ty::db::HirDatabase>::generic_defaults
  32: hir_ty::lower::substs_from_path_segment
  33: hir_ty::lower::<impl hir_ty::TraitRef>::from_resolved_path
  34: hir_ty::lower::<impl hir_ty::TraitRef>::from_path
  35: hir_ty::lower::<impl hir_ty::TraitRef>::from_hir
  36: hir_ty::lower::impl_trait_query
  37: salsa::runtime::Runtime::execute_query_implementation
  38: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  39: salsa::derived::slot::Slot<Q,MP>::read
  40: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  41: <DB as hir_ty::db::HirDatabase>::impl_trait::__shim
  42: <DB as hir_ty::db::HirDatabase>::impl_trait
  43: hir_ty::method_resolution::TraitImpls::trait_impls_in_crate_query
  44: salsa::runtime::Runtime::execute_query_implementation
  45: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  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>::trait_impls_in_crate::__shim
  49: hir_ty::method_resolution::TraitImpls::trait_impls_in_deps_query
  50: salsa::runtime::Runtime::execute_query_implementation
  51: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  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>::trait_impls_in_deps::__shim
  55: hir_ty::traits::chalk::<impl chalk_solve::RustIrDatabase<hir_ty::traits::chalk::interner::Interner> for hir_ty::traits::ChalkContext>::impls_for_trait
  56: chalk_solve::clauses::program_clauses_for_goal
  57: <chalk_recursive::recursive::Solver<I> as chalk_recursive::solve::SolveDatabase<I>>::solve_goal
  58: <chalk_recursive::recursive::RecursiveSolver<I> as chalk_solve::solve::Solver<I>>::solve_limited
  59: hir_ty::traits::trait_solve_query
  60: salsa::runtime::Runtime::execute_query_implementation
  61: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  62: salsa::derived::slot::Slot<Q,MP>::read
  63: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  64: <DB as hir_ty::db::HirDatabase>::trait_solve::__shim
  65: <DB as hir_ty::db::HirDatabase>::trait_solve
  66: hir_ty::autoderef::deref
  67: <core::iter::sources::successors::Successors<T,F> as core::iter::traits::iterator::Iterator>::next
  68: core::iter::traits::iterator::Iterator::find_map
  69: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  70: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  71: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  72: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  73: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  74: hir_ty::infer::infer_query
  75: salsa::runtime::Runtime::execute_query_implementation
  76: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  77: salsa::derived::slot::Slot<Q,MP>::read
  78: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  79: <DB as hir_ty::db::HirDatabase>::infer_query::__shim
  80: hir_ty::db::infer_wait
  81: hir_ty::diagnostics::validate_body
  82: hir::code_model::Function::diagnostics
  83: hir::code_model::Module::diagnostics
  84: ide::diagnostics::diagnostics
  85: std::panicking::try
  86: ide::Analysis::diagnostics
  87: rust_analyzer::handlers::handle_code_action
  88: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I also get this panic when using rust-analyzer in vscode.

This seems to have started happening with recently nightly rustc (and now also beta).

I first observed this in rustc 1.53.0-nightly (727d10156 2021-04-27) with the last version where I didn't see this happen being rustc 1.53.0-nightly (7f4afdf02 2021-04-22).

Note, it matters what version of rustc is currently in use on the system, not version rust-analyzer was compiled with.

2892 has a similar error message, however the stack looks moderately different, so I figured I'd raise a separate issue.

flodiebold commented 3 years ago

This is a duplicate of #8686, which is fixed in current versions. Installing current stable or nightly should fix this.

flodiebold commented 3 years ago

Interesting that you use rust-analyzer in evcxr by the way, feel free to give feedback about the APIs!