]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #90291 - geeklint:loosen_weak_debug_bound, r=dtolnay
authorbors <bors@rust-lang.org>
Sun, 8 Jan 2023 22:40:38 +0000 (22:40 +0000)
committerbors <bors@rust-lang.org>
Sun, 8 Jan 2023 22:40:38 +0000 (22:40 +0000)
Loosen the bound on the Debug implementation of Weak.

Both `rc::Weak<T>` and `sync::Weak<T>` currently require `T: Debug` in their own `Debug` implementations, but they don't currently use it;  they only ever print a fixed string.

A general implementation of Debug for Weak that actually attempts to upgrade and rely on the contents is unlikely in the future because it may have unbounded recursion in the presence of reference cycles, which Weak is commonly used in.  (This was the justification for why the current implementation [was implemented the way it is](https://github.com/rust-lang/rust/pull/19388/commits/f0976e2cf3f6b0027f118b791e0888b29fbb41a7)).

When I brought it up [on the forum](https://internals.rust-lang.org/t/could-the-bound-on-weak-debug-be-relaxed/15504), it was suggested that, even if an implementation is specialized in the future that relies on the data stored within the Weak, it would likely rely on specialization anyway, and could therefore easily specialize on the Debug bound as well.

1  2 
library/alloc/src/rc.rs
library/alloc/src/sync.rs

Simple merge
Simple merge