Just thought I'd post this reminder that the null-pointer optimization exists and if you're not careful (like I wasn't) you can create some very confusing situations. I guess the lesson is not to lie to the compiler.
use std::{ptr, slice};
fn main() {
// Should be fine because the pointer's never dereferenced because the
// length is zero, or so you'd think.
let slice: &[u8] = unsafe {
slice::from_raw_parts(ptr::null(), 0)
};
// It's obviously okay!
let obviously_okay: Result<_, ()> = Ok(slice);
// Or not.
println!("Is it okay? {:?}", obviously_okay.is_ok());
// => Is it okay? false
}