more explicit types
[web.git] / ralf / _posts / 2018-11-16-stacked-borrows-implementation.md
index 211d21d32e9a08bb377e33f02c37da017fc00b7d..f8f49506727cdf5c9b37a69f63ade5fae063db9f 100644 (file)
@@ -1,6 +1,7 @@
 ---
 title: "Stacked Borrows Implemented"
 categories: internship rust
 ---
 title: "Stacked Borrows Implemented"
 categories: internship rust
+forum: https://internals.rust-lang.org/t/stacked-borrows-implemented/8847
 ---
 
 Three months ago, I proposed [Stacked Borrows]({% post_url
 ---
 
 Three months ago, I proposed [Stacked Borrows]({% post_url
@@ -568,7 +569,7 @@ code:
 
 {% highlight rust %}
 fn demo_refcell() {
 
 {% highlight rust %}
 fn demo_refcell() {
-  let rc = &mut RefCell::new(23u8);
+  let rc: &mut RefCell<u8> = &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.
   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.
@@ -576,22 +577,22 @@ fn demo_refcell() {
 
   // Taking a shared reference shares the location but does not freeze, due
   // to the `UnsafeCell`.
 
   // Taking a shared reference shares the location but does not freeze, due
   // to the `UnsafeCell`.
-  let rc_shr = &*rc;
+  let rc_shr: &RefCell<u8> = &*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.
   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<u8> = rc_shr.borrow_mut();
   
   // Obtain a mutable reference into the `RefCell`.
   
   // 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.
   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<u8> = &*rc; // tag gets changed to `Shr(Some(3))`
   Retag(shr_ref);
   // stack: [Uniq(0), Shr]; not frozen
 
   Retag(shr_ref);
   // stack: [Uniq(0), Shr]; not frozen
 
@@ -907,5 +908,11 @@ significantly reduce my Rust activities in favor of finishing my PhD.  I won't
 disappear entirely though, don't worry -- I will still be able to mentor you if
 you want to help with any of the above tasks. :)
 
 disappear entirely though, don't worry -- I will still be able to mentor you if
 you want to help with any of the above tasks. :)
 
-Thanks to @nikomatsakis for feedback on a draft of this post.
-<!-- If you want to help or report results of your experiments, if you have any questions or comments, please join the [discussion in the forums](). -->
+Thanks to @nikomatsakis for feedback on a draft of this post, to @shepmaster for
+making miri available on the playground, and to @oli-obk for reviewing all my
+PRs at unparalleled speed. <3
+
+If you want to
+help or report results of your experiments, if you have any questions or
+comments, please join the
+[discussion in the forums](https://internals.rust-lang.org/t/stacked-borrows-implemented/8847).