Skip to content

Rust-analyzer hangs on file with cyclic traits #12897

Closed
@RobinStoll

Description

@RobinStoll

rust-analyzer version: rust-analyzer 0.4.1143-standalone (4087535 2022-07-27)
rustc version: rustc 1.62.1 (e092d0b6b 2022-07-16)

Reproduction

  1. In a fresh cargo directory, replace src/main.rs by the following
pub trait A {
    type X: B;
}

pub trait B {
    type Y: A<X = Self>;
}

pub fn foo<T: A>()
  where T::X: Clone
{
    foo()
}

fn main() {}
  1. Call rust-analyzer analysis-stats .

Result

rust-analyzer outputs

Database loaded:     519.19ms, 61minstr (metadata 344.05ms, 730kinstr; build 137.29ms, 302kinstr)
  crates: 1, mods: 1, decls: 4, fns: 2
Item Collection:     3.14s, 19ginstr
0/2 0% processing: foo

and then hangs, continuing to use 100% of one CPU core.

Stack trace

Here's the output of a stack trace generated by gdb for the hanging process:

Thread 1 (Thread 0x7f805c3ecb00 (LWP 28483) "rust-analyzer"):
#0  0x000055a915d386b4 in <chalk_ir::TyData<I> as core::hash::Hash>::hash ()
#1  0x000055a915cd3657 in <hir_ty::interner::Interner as chalk_ir::interner::Interner>::intern_ty ()
#2  0x000055a915da51cf in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
#3  0x000055a915d867bb in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter ()
#4  0x000055a915d5531f in chalk_recursive::fulfill::Fulfill<I,Solver>::prove ()
#5  0x000055a915d55cf9 in chalk_recursive::fulfill::Fulfill<I,Solver>::solve ()
#6  0x000055a915e0456e in chalk_recursive::solve::SolveIteration::solve_iteration ()
#7  0x000055a915ca701b in chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal ()
#8  0x000055a915d553ff in chalk_recursive::fulfill::Fulfill<I,Solver>::prove ()
#9  0x000055a915d55cf9 in chalk_recursive::fulfill::Fulfill<I,Solver>::solve ()
#10 0x000055a915e0456e in chalk_recursive::solve::SolveIteration::solve_iteration ()
#11 0x000055a915ca701b in chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal ()
#12 0x000055a915d553ff in chalk_recursive::fulfill::Fulfill<I,Solver>::prove ()
#13 0x000055a915d55cf9 in chalk_recursive::fulfill::Fulfill<I,Solver>::solve ()
#14 0x000055a915e0456e in chalk_recursive::solve::SolveIteration::solve_iteration ()
#15 0x000055a915ca701b in chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal ()
#16 0x000055a915ca7feb in chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal ()
#17 0x000055a915dcbc2a in <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute ()
#18 0x000055a915e17467 in salsa::runtime::Runtime::execute_query_implementation ()
#19 0x000055a915c4a40d in salsa::derived::slot::Slot<Q,MP>::read_upgrade ()
#20 0x000055a915c6b490 in salsa::derived::slot::Slot<Q,MP>::read ()
#21 0x000055a915ce5818 in <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch ()
#22 0x000055a915caf0d0 in salsa::QueryTable<Q>::get ()
#23 0x000055a91650bf25 in <DB as hir_ty::db::HirDatabase>::trait_solve_query ()
#24 0x000055a915dc51d4 in hir_ty::db::trait_solve_wait ()
#25 0x000055a91650bcac in <DB as hir_ty::db::HirDatabase>::trait_solve ()
#26 0x000055a915e20a71 in hir_ty::infer::unify::InferenceTable::register_obligation_in_env::hfc53f915e21eb152 ()
#27 0x000055a915e492db in hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::register_obligations_for_call ()
#28 0x000055a915e3f501 in hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner ()
#29 0x000055a915e3acd8 in hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce ()
#30 0x000055a915e46b1b in hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block ()
#31 0x000055a915e3dc50 in hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner ()
#32 0x000055a915e3acd8 in hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce ()
#33 0x000055a915e4e02b in hir_ty::infer::infer_query ()
#34 0x000055a915e14a62 in salsa::runtime::Runtime::execute_query_implementation ()
#35 0x000055a915c2bf3e in salsa::derived::slot::Slot<Q,MP>::read_upgrade ()
#36 0x000055a915c69cbf in salsa::derived::slot::Slot<Q,MP>::read ()
#37 0x000055a915ce5c0e in <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch ()
#38 0x000055a915cae0a8 in salsa::QueryTable<Q>::get ()
#39 0x000055a91650bc22 in <DB as hir_ty::db::HirDatabase>::infer_query ()
#40 0x000055a915dc50cf in hir_ty::db::infer_wait ()
#41 0x000055a916597c86 in rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run_inference ()
#42 0x000055a916595b5d in rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run ()
#43 0x000055a91677c2bb in rust_analyzer::main ()
#44 0x000055a916770d23 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
#45 0x000055a91678d879 in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h58386d473fcb43f3 ()
#46 0x000055a9167e987e in core::ops::function::impls::{impl#2}::call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> () at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:280
#47 std::panicking::try::do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> () at library/std/src/panicking.rs:492
#48 std::panicking::try<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> () at library/std/src/panicking.rs:456
#49 std::panic::catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> () at library/std/src/panic.rs:137
#50 std::rt::lang_start_internal::{closure#2} () at library/std/src/rt.rs:128
#51 std::panicking::try::do_call<std::rt::lang_start_internal::{closure_env#2}, isize> () at library/std/src/panicking.rs:492
#52 std::panicking::try<isize, std::rt::lang_start_internal::{closure_env#2}> () at library/std/src/panicking.rs:456
#53 std::panic::catch_unwind<std::rt::lang_start_internal::{closure_env#2}, isize> () at library/std/src/panic.rs:137
#54 std::rt::lang_start_internal () at library/std/src/rt.rs:128
#55 0x000055a91677fea2 in main ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions