Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIR borrowck: implement union-and-array-compatible semantics #46268

Merged
merged 11 commits into from
Dec 6, 2017
6 changes: 4 additions & 2 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
@@ -1084,9 +1084,11 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
pub fn map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> RefMut<'b, U>
where F: FnOnce(&mut T) -> &mut U
{
// FIXME: fix borrow-check
let RefMut { value, borrow } = orig;
RefMut {
value: f(orig.value),
borrow: orig.borrow,
value: f(value),
borrow: borrow,
}
}
}
18 changes: 12 additions & 6 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
@@ -1776,12 +1776,18 @@ impl<I: Iterator> Iterator for Peekable<I> {

#[inline]
fn nth(&mut self, n: usize) -> Option<I::Item> {
match self.peeked.take() {
// the .take() below is just to avoid "move into pattern guard"
Some(ref mut v) if n == 0 => v.take(),
Some(None) => None,
Some(Some(_)) => self.iter.nth(n - 1),
None => self.iter.nth(n),
// FIXME: merge these when borrow-checking gets better.
if n == 0 {
match self.peeked.take() {
Some(v) => v,
None => self.iter.nth(n),
}
} else {
match self.peeked.take() {
Some(None) => None,
Some(Some(_)) => self.iter.nth(n - 1),
None => self.iter.nth(n),
}
}
}