matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.84k stars 110 forks source link

Fixed `LateInit` recipe stack overflow #212

Closed jack-cooper closed 1 year ago

jack-cooper commented 1 year ago

The given LateInit recipe works up until the print statement, which causes a stack overflow as the derived Debug implementation tries to write out:

LateInit { cell: OnceCell(A { b: LateInit { cell: OnceCell(B { a: LateInit // repeats endlessly from here

To fix this, I've added in a rudimentary Debug impl.

matklad commented 1 year ago

:thinking: yeah, ideally even silly examples would do something reasonable. I'd like to aviod adding custom code for debug here -- destracts from the thrust of the example. Can we rework this somehow to keep it simple? maybee use something like let _a = a.b.a.b.a instead of print?

jack-cooper commented 1 year ago

Sounds sensible to me! Most recent commit removes the Debug impls.

matklad commented 1 year ago

Nice, thanks!

bors r+

bors[bot] commented 1 year ago

Build succeeded: