From 351dcf54d4afe8ff5baa83672d36531c0d3e901a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 21 Nov 2018 09:16:41 +0100 Subject: [PATCH] more explicit types --- .../2018-11-16-stacked-borrows-implementation.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/personal/_posts/2018-11-16-stacked-borrows-implementation.md b/personal/_posts/2018-11-16-stacked-borrows-implementation.md index e842044..f8f4950 100644 --- a/personal/_posts/2018-11-16-stacked-borrows-implementation.md +++ b/personal/_posts/2018-11-16-stacked-borrows-implementation.md @@ -569,7 +569,7 @@ code: {% highlight rust %} fn demo_refcell() { - let rc = &mut RefCell::new(23u8); + let rc: &mut RefCell = &mut RefCell::new(23u8); Retag(rc); // tag gets changed to `Uniq(0)` // We will consider the stack of the location where `23` is stored; the // `RefCell` bookkeeping counters are not of interest. @@ -577,22 +577,22 @@ fn demo_refcell() { // Taking a shared reference shares the location but does not freeze, due // to the `UnsafeCell`. - let rc_shr = &*rc; + let rc_shr: &RefCell = &*rc; Retag(rc_shr); // tag gets changed to `Shr(Some(1))` // stack: [Uniq(0), Shr]; not frozen // Lots of stuff happens here but it does not matter for this example. - let mut bmut = rc_shr.borrow_mut(); + let mut bmut: RefMut = rc_shr.borrow_mut(); // Obtain a mutable reference into the `RefCell`. - let mut_ref = &mut *bmut; + let mut_ref: &mut u8 = &mut *bmut; Retag(mut_ref); // tag gets changed to `Uniq(2)` // stack: [Uniq(0), Shr, Uniq(2)]; not frozen // And at the same time, a fresh shared reference to its outside! // This counts as a read access through `rc`, so we have to pop until // at least a `Shr` is at the top of the stack. - let shr_ref = &*rc; // tag gets changed to `Shr(Some(3))` + let shr_ref: &RefCell = &*rc; // tag gets changed to `Shr(Some(3))` Retag(shr_ref); // stack: [Uniq(0), Shr]; not frozen -- 2.30.2