Why this matters
The bug. Rust's RwLock allows many readers OR one writer. The read guard names lives until the end of the enclosing block. Calling state.write() while names is alive means the writer call blocks waiting for the reader to drop — but the reader doesn't drop until the writer call returns. Deadlock.
The fix. Drop names explicitly *before* asking for the writer. Or extract the data you need from the read guard, drop it, then write.
Subtle. Single-threaded code can't deadlock on Mutex (unwrap panics on contention by the same thread), but RwLock very much can — it patiently waits forever, looking exactly like a hung process.
Review heuristic
Any function that acquires more than one lock, holds onto the first while waiting for the second, and isn't ordered consistently with every other function that touches those locks — that's a deadlock waiting for the right two requests to arrive together.
External reference: CWE-833: Deadlock.