kernel icon indicating copy to clipboard operation
kernel copied to clipboard

Treat raw pointers with more respect

Open hawkw opened this issue 8 years ago • 1 comments

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 Unique in some cases
    • I think there might be more uses of raw pointers that can be replaced with Unique.
  • 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() or pointer.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
  • where can mem::transmute-ting a reference into a raw pointer be replaced with &*?
    • this is more idiomatic

hawkw avatar Feb 04 '17 15:02 hawkw

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...

hawkw avatar Feb 04 '17 15:02 hawkw