about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-12-15 05:40:12 +0000
committerbors <bors@rust-lang.org>2017-12-15 05:40:12 +0000
commit84feab34e455722061bb55260eafd1eb02a538fa (patch)
tree0a791087fcd4e939afeef853e32693170bf3e0e3 /src/librustc_data_structures
parent933103190950c97b966e789e9206bff2f7bd6118 (diff)
parent159037e05383f2349a709aa1c1681f11f89c552a (diff)
Auto merge of #46537 - pnkfelix:two-phase-borrows, r=arielb1
[MIR-borrowck] Two phase borrows

This adds limited support for two-phase borrows as described in
  http://smallcultfollowing.com/babysteps/blog/2017/03/01/nested-method-calls-via-two-phase-borrowing/

The support is off by default; you opt into it via the flag `-Z two-phase-borrows`

I have written "*limited* support" above because there are simple variants of the simple `v.push(v.len())` example that one would think should work but currently do not, such as the one documented in the test compile-fail/borrowck/two-phase-reservation-sharing-interference-2.rs

(To be clear, that test is not describing something that is unsound. It is just providing an explicit example of a limitation in the implementation given in this PR. I have ideas on how to fix, but I want to land the work that is in this PR first, so that I can stop repeatedly rebasing this branch.)
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/indexed_set.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs
index 5d7139507b3..223e08de826 100644
--- a/src/librustc_data_structures/indexed_set.rs
+++ b/src/librustc_data_structures/indexed_set.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::borrow::{Borrow, BorrowMut, ToOwned};
 use std::fmt;
 use std::iter;
 use std::marker::PhantomData;
@@ -73,6 +74,25 @@ pub struct IdxSet<T: Idx> {
     bits: [Word],
 }
 
+impl<T: Idx> Borrow<IdxSet<T>> for IdxSetBuf<T> {
+    fn borrow(&self) -> &IdxSet<T> {
+        &*self
+    }
+}
+
+impl<T: Idx> BorrowMut<IdxSet<T>> for IdxSetBuf<T> {
+    fn borrow_mut(&mut self) -> &mut IdxSet<T> {
+        &mut *self
+    }
+}
+
+impl<T: Idx> ToOwned for IdxSet<T> {
+    type Owned = IdxSetBuf<T>;
+    fn to_owned(&self) -> Self::Owned {
+        IdxSet::to_owned(self)
+    }
+}
+
 impl<T: Idx> fmt::Debug for IdxSetBuf<T> {
     fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
         w.debug_list()