|
|
|
|
|
by a1369209993
2314 days ago
|
|
> [1] https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html Thanks. > having Option<&[T]> be the same size as &[T] That is literally what I mentioned as a possible reason ("except possibly ..."), but what I overlooked was that you could take a mutable reference to the &[T] inside a Option<&[T]>, then store a valid &[T] into it - if NULL is allowed, you effectively mutated the discriminant of a enum when you have active references to its fields, violating some aspect of type/memory safety, even I'm not sure which. > C generally chooses NULL, Rust happens to choose a different value. It's not about what pointer value the langauge chooses when it's asked to create a zero-length slice, it's about whether the language accepts a NULL pointer in a zero-length slice it finds lying around somewhere. |
|