Skip to content

Trying to debug print the difference of two BTreeSets goes into endless print loop. #41338

Closed
@mrkajetanp

Description

@mrkajetanp

I tried printing difference of two BTreeSets using the debug print, but instead of printing anything useful it went into some weird recursive loop printing Difference(Difference(Difference endlessly.

I tried this code:

let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);

let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);

println!("{:?}", a.difference(&b));

I obviously expected it to print something like Difference(contents) just like when debug printing some vec.iter().

Instead, it started printing this:

Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference(Difference

It wouldn't stop until I killed the process.

I read the source file set.rs and I couldn't find any Debug implementation or derivation for Difference struct so I think it might be related somehow. I don't really know how it compiles without Debug being implemented / derived on this struct but I don't understand how language intrinsics work just yet.

Meta

`rustc --version --verbose
rustc 1.18.0-nightly (28a7429 2017-04-13)
binary: rustc
commit-hash: 28a7429
commit-date: 2017-04-13
host: x86_64-apple-darwin
release: 1.18.0-nightly
LLVM version: 3.9'

It doesn't panic so there's no backtrace to put here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions