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 
4
  • 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<Self> being called a smart pointer, but not many people know you can use that as self. Commented Dec 3, 2016 at 1:35
  • 1
    As fas as i understand references generate noalias flag and this flag cause some optimizations. Commented Dec 3, 2016 at 1: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) Commented Dec 5, 2016 at 8: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. Commented Dec 7, 2016 at 23:16

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.