4

It would be good when we want to use method syntax and disable smart pointer optimizations.

fn foo(*const self) // this would not let smart pointer optimizations
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ttarikbnr
  • 73
  • 7
  • 4
    *and disable smart pointer optimizations* — what "optimizations" do you think `&self` or `&mut self` perform? Also, `&self` and `&mut self` are not "smart pointers". I could see `Box` being called a smart pointer, [but not many people know you can use that as `self`](http://stackoverflow.com/q/25462935/155423). – Shepmaster Dec 03 '16 at 01:35
  • 1
    As fas as i understand references generate noalias flag and this flag cause some optimizations. – ttarikbnr Dec 03 '16 at 01:42
  • only `&mut` references generate `noalias` (and afaik even that has been turned off until further notice due to llvm bugs). Could you please share your use case (a code example that shows why `&self` doesn't work) – oli_obk Dec 05 '16 at 08:20
  • Only &T references generate noalias atm. I asked a question if &mut T generate noalias in the future on www.reddit.com/r/rust. And they said that after some llvm bugs get fixed it will generate noalias too. I wanna write some unsafe methods and because its unsafe i wanna turn reference optimizations(noalias, nocapture) off like UnsafeCell semantics. – ttarikbnr Dec 07 '16 at 23:16

2 Answers2

5

Because nobody has requested it, which probably means that nobody cared much for it.

Note that since the unsafe semantics of Rust have not been finalized, it may not be a good idea to bet that aliasing is fine, anyway.

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
0

I use to do this, for example in case of *const T


/// Consider that Self is a struct composed of f64 fields, like a vector

pub fn foo(&self) {
    let self_ptr = self as *const Self as *const f64;
}