Guest User

Untitled

a guest
Jul 17th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. fn foo(x: &mut u32, y: usize, f: fn(usize)) -> u32 {
  2. *x = 42;
  3. f(y);
  4. *x // can we optimize this to 42?
  5. }
  6.  
  7. fn main() {
  8. let mut x = Box::new(0);
  9. let x_ptr = &mut *x as *mut u32;
  10. foo(&mut *x, x_ptr as usize, |y| unsafe { *(y as *mut u32) = 23; } );
  11. }
Add Comment
Please, Sign In to add comment