Rust compilation errors Brain Teaser
- https://stackoverflow.com/a/42264074 * and Deref, *box special case
- The way to mutably borrow an Option<&mut >https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=11934a93d8e2a0fb98a98874e73ae78f
- What exactly is the first error? I think it’s move away while &mut borrowed.
- upstream may add new impl for trait
- Self … can not be made into trait object
- Can only implement trait of current crate or for struct of current crate.
- Self … flow into … with mismatched lifetime …
- method(&’a self) -> Vec<&’a T>: &mut borrowed in function call makes it impossible to be returned, unless the borrow has the lifetime of ‘a.
- https://users.rust-lang.org/t/cfg-test-doesnt-propagate-to-external-crates/13046
- HashMap can not infer type ‘S’.
- Errors can be chained, but when some layer think it can handle or transform some error, which error does it handle, the original, or direct error, or some error in the middle?
- fn is_valid<'this: 'pred_param, 'pred_param>(
| 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 <https://github.com/rust-lang/rust/issues/35203>
Drop a Lock
let lock = &mut *mutex.lock(); // <== here is wrong
// let lock = &mut mutex.lock() // <= this is also wrong.
If sth {
drop(lock);
// 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.