3 ms·
Rust is full of weird quirks that defenders explain by saying that "the compiler isn't smart enough yet." They often seem like consequences of a "compiler-defin
by legerdemain 4y ago
Rust is full of weird quirks that defenders explain by saying that "the compiler isn't smart enough yet." They often seem like consequences of a "compiler-defined" implementation. One random example -- this compiles and runs:
#![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)
}
- afdbcreid 4y agoIn my experience, this quirks don't appear in real life (at least unless you do bunch of trait metaprogramming). One exception is async code, since it stretches the type system you are far more likely to enter some obfuscated lifetime or trait error. 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).