Skip to content

Commit 4c99ce4

Browse files
committed
std: explain unconventional choice of let-else binding over while-let loop
1 parent 1d002c3 commit 4c99ce4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

std/src/sys/windows/thread_local_key.rs

Lines changed: 3 additions & 0 deletions
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)