logoalt Hacker News

kouteiheikayesterday at 2:42 PM2 repliesview on HN

Yes. All `&mut` references in Rust are equivalent to C's `restrict` qualified pointers. In the past I measured a ~15% real world performance improvement in one of my projects due to this (rustc has/had a flag where you can turn this on/off; it was disabled by default for quite some time due to codegen bugs in LLVM).


Replies

steveklabnikyesterday at 2:45 PM

Not just all &mut T, but also all &T, where the T does not transitively contain an UnsafeCell<T>. Click "show llvm ir" instead of "build" here: https://play.rust-lang.org/?version=stable&mode=release&edit...

show 1 reply
dmitrygrtoday at 2:53 AM

Do you not use restrict in your normal everyday C code that you write? I use it in my normal C code.

show 1 reply