If you want a much more annoying example of inconsistency in the initial language design, look at the behaviour of nil and closed channels:
- sending data to a nil channel blocks forever;
- receiving data from a nil channel blocks forever;
- sending data to a closed channel causes a panic;
- receiving data from a closed channel is fine: you receive the zero value, forever.
I can understand the logic behind the last two (sending to a closed channel is an error in program logic, and closing a channel is a common idiom for broadcasting completion of a task to several goroutines), but the first two are just a massive footgun, and, in my opinion, should cause panics instead.
#![allow(unused)]
pub fn main() {
let mut x = vec![1, 2, 3];
let y = &mut x;
let z: &mut _ = y;
println!("{:?}", y)
}
This does not: #![allow(unused)]
pub fn main() {
let mut x = vec![1, 2, 3];
let y = &mut x;
let z = y;
println!("{:?}", y)
}That being said, I was quite surprised this doesn't compile... (I understand why, but I expected the compiler to have all required information to perform reborrowing).