kernel
kernel copied to clipboard
Treat raw pointers with more respect
I think there are at least a few cases where we can work on refactoring code that uses raw pointers to be somewhat more idiomatic:
- where can raw pointers be replaced with
ptr::Unique<T>s?- We already use
Uniquein some cases - I think there might be more uses of raw pointers that can be replaced with
Unique.
- We already use
- where can pointer math be replaced with
pointer.offset()?- this is considered more idiomatic
- has less ugly casts/can be less wordy
- where can coercing raw pointers to references be replaced with
pointer.as_ref()orpointer.as_mut()?- these functions can still return references to uninitialised memory, but they're more null-safe (allow us to handle null pointers
Optionally) - fewer ugly casts/transmutes
- these functions can still return references to uninitialised memory, but they're more null-safe (allow us to handle null pointers
- where can
mem::transmute-ting a reference into a raw pointer be replaced with&*?- this is more idiomatic
Another way we could potentially improve safety is by 'downgrading' some *mut pointers to *const pointers. Potentially, there might also be some *const pointers that could be downgraded to &'static references...