Rust compilation errors Brain Teaser

|        let mut map = HashMap::default();

|            -------------------   ^^^^^^^^^^^^^^^^ cannot infer type for `S`

|            |

|            consider giving `map` the explicit type `std::collections::HashMap<.., .., .., S>`, where the type parameter `S` is specified      

patterns aren't allowed in methods without bodies

|    fn commit(mut self, parent: &mut Self) -> Result<()>;

|              ^^^^^^^^


= note: #[warn(patterns_in_fns_without_body)] on by default

= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

= note: for more information, see issue #35203 <>

Drop a Lock

let lock = &mut *mutex.lock(); // <== here is wrong

// let lock = &mut mutex.lock() // <= this is also wrong.

If sth {


// Do sth, however lock is not released as expected.


This is correct: let mut lock = mutex.lock()

Sender Receiver

The Sender can be cloned to send to the same channel multiple times, but only one Receiver is supported.

Sometimes you want to be able to receive from different threads? Especially when you are maintaining the task queue by fetching the receiver with try_recv() then push into an internal task queue from multiple threads.

Lifetime in traits, 2 consecutive trait calls make it unable to compile

See verify_snapshot_db. Compiler error: key_value_iter does not live long enough.

Range for Vec<T> keyed BTreeMap