Slide 1

Slide 1 text

Rust Under the Rug

Slide 2

Slide 2 text

Software Engineer at Tuenti MadRust co-organizer  jrvidal  _rvidal

Slide 3

Slide 3 text

[rust-dev] RFC: Updated RFC process Brian Anderson banderson at mozilla.com Tue Mar 11 18:11:48 PDT 2014 Hey, Rusties. The freewheeling way that we add new features to Rust has been good for early development [...] @brson

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

What "imperfections"? Sebastian Lengauer

Slide 6

Slide 6 text

What curiosities

Slide 7

Slide 7 text

Leakpocalypse Auto traits Implicit bounds

Slide 8

Slide 8 text

Leakpocalypse

Slide 9

Slide 9 text

#[lang = "drop"] trait Drop { fn drop(&mut self); }

Slide 10

Slide 10 text

// libcore/mem.rs unsafe fn forget(t: T) { intrinsics::forget(t) }

Slide 11

Slide 11 text

struct Leak { cycle: RefCell>>>>, data: T, } fn safe_forget(data: T) { let e = Rc::new(Leak { cycle: RefCell::new(None), data: data, }); // Create a cycle *e.cycle.borrow_mut() = Some( Rc::new(e.clone()) ); } @gankro

Slide 12

Slide 12 text

let mut v = Box::new(10); { let reference = &*v; let jg = thread::scoped(move || { println!("{}", reference); }); safe_forget(jg); } *v = 20;

Slide 13

Slide 13 text

// libcore/mem.rs fn forget(t: T) { unsafe { intrinsics::forget(t) } }

Slide 14

Slide 14 text

Auto Traits General Motors

Slide 15

Slide 15 text

unsafe auto trait Send {} #[lang="sync"] unsafe auto trait Sync {}

Slide 16

Slide 16 text

// Automatic (non-)implementations struct Sendable { numbers: Vec } struct NonSendable { shared: Rc } // Overrides struct YouCanSendThis { numbers: *const usize } unsafe impl Send for YouCanSendThis {} struct DontSendThis { numbers: Vec } impl !Send for DontSendThis {} // Unstable RFCs #19, #127

Slide 17

Slide 17 text

pub struct Banana { /* normal stuff */ }

Slide 18

Slide 18 text

pub struct Banana { /* normal(?) stuff */ } unsafe impl Send for Banana {}

Slide 19

Slide 19 text

pub struct Banana { /* normal(?) stuff */ } trait SendForReal : Send {} impl SendForReal for Banana {}

Slide 20

Slide 20 text

let m = Mutex::new(Cell::new(0)); let g : MutexGuard> = m.lock().unwrap(); { rayon::join( || { g.set(g.get() + 1) }, || { g.set(g.get() + 1) }); } @RalfJung

Slide 21

Slide 21 text

?Sized Nikolai Chernichenko

Slide 22

Slide 22 text

#[lang = "sized"] trait Sized {}

Slide 23

Slide 23 text

enum Option { /* ... */ } struct Rc where T: ?Sized { /* ... */ }

Slide 24

Slide 24 text

fn my_api() where T : ?Sized + ?Move + ?Leak + ?DynSize More implicit bounds RFC

Slide 25

Slide 25 text

unsafe auto trait Unpin {} Unpin RFC

Slide 26

Slide 26 text

More! #[fundamental] Specialization DerefMove and *boxed Read::chars

Slide 27

Slide 27 text

Bibliography What's a lang item Nomicon catch_panic RFC, on different types of guarantees.

Slide 28

Slide 28 text

Keep Calm and Read RFCs Thanks!