Skip to content

Commit 88efb1b

Browse files
committed
std: explain unconventional choice of let-else binding over while-let loop
1 parent 65c66a1 commit 88efb1b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/std/src/sys/windows/thread_local_key.rs

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ unsafe fn run_keyless_dtors() {
4343
// guarantee that a TLS key cannot be set after it is flagged for
4444
// destruction.
4545
loop {
46+
// Use a let-else binding to ensure the `RefCell` guard is dropped
47+
// immediately. Otherwise, a panic would occur if a TLS destructor
48+
// tries to access the list.
4649
let Some((ptr, dtor)) = DESTRUCTORS.borrow_mut().pop() else {
4750
break;
4851
};

0 commit comments

Comments
 (0)