rustc performs auto-ref when a raw pointer would be enough · Issue #73987 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
The following code:
#![feature(slice_ptr_len)]
pub struct Test { data: [u8], }
pub fn test_len(t: *const Test) -> usize { unsafe { (*t).data.len() } }
generates MIR like
_2 = &((*_1).0: [u8]);
_0 = const core::slice::<impl [u8]>::len(move _2) -> bb1;
This means that a reference to data
gets created, even though a raw pointer would be enough. That is a problem because creating a reference makes aliasing and validity assumptions that could be avoided. It would be better if rustc would not implicitly introduce such assumptions.