Skip to content

Commit

Permalink
std: explain unconventional choice of let-else binding over while-let…
Browse files Browse the repository at this point in the history
… loop
  • Loading branch information
joboet committed Oct 9, 2023
1 parent 65c66a1 commit 88efb1b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/std/src/sys/windows/thread_local_key.rs
Expand Up @@ -43,6 +43,9 @@ unsafe fn run_keyless_dtors() {
// guarantee that a TLS key cannot be set after it is flagged for
// destruction.
loop {
// Use a let-else binding to ensure the `RefCell` guard is dropped
// immediately. Otherwise, a panic would occur if a TLS destructor
// tries to access the list.
let Some((ptr, dtor)) = DESTRUCTORS.borrow_mut().pop() else {
break;
};
Expand Down

0 comments on commit 88efb1b

Please sign in to comment.