Does this stack overflow for anyone else?

fn test_01() {
    let mut ans = im::Vector::new();

    for i in 0..10_000 {
    for i in 0..10_000 {

    ans.sort_by(|lhs, rhs| lhs.cmp(rhs));}

Does this stackoverflow for anyone else?

I am running on x86_64 linux

rustc --version
rustc 1.51.0 (2fd73fabe 2021-03-23)

using dependency:

im = { version = "15.0.0", features = ["serde"] }
1 Like

Yes, it stack overflows for me as well. My guess is that this is because the destructor ends up recursing 10000 times. See this post for a similar situation with linked lists.

Also, please rustfmt your code before you post it.


Thanks for verifying.

Have you run this under gdb? For me, it points to src/, a line having to deal with picking the pivot.

No, I haven't. It was just a guess based on the fact that im uses a tree structure internally.

sort_by does indeed recurse:

Sounds like you have to file a bug report.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.