Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
mrkajetanp opened this issue Apr 17, 2017 · 3 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@mrkajetanp
Copy link
Contributor

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.

@sfackler
Copy link
Member

Debug is implemented here: https://github.com/rust-lang/rust/blob/master/src/libcollections/btree/set.rs#L141. Seems like a pretty straightforward infinite recursion to me. Added in #39002 - cc @GuillaumeGomez

@sfackler sfackler added I-wrong T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 17, 2017
@GuillaumeGomez
Copy link
Member

Oh indeed, my bad. Fixing it.

@TimNN
Copy link
Contributor

TimNN commented Apr 17, 2017

This effects beta as well.

bors added a commit that referenced this issue Apr 20, 2017
@GuillaumeGomez GuillaumeGomez added beta-nominated Nominated for backporting to the compiler in the beta channel. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Apr 22, 2017
@alexcrichton alexcrichton removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 10, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants