librustc: Implement write guards for borrowing @mut to & or &mut. r=nmatsakis
This commit is contained in:
parent
8bde2c1d65
commit
f405e41d7a
38 changed files with 522 additions and 365 deletions
|
|
@ -430,9 +430,9 @@ impl<T: Const Owned> &RWWriteMode<T> {
|
|||
/// Access the pre-downgrade RWARC in write mode.
|
||||
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
|
||||
match *self {
|
||||
RWWriteMode((data, ref token, _)) => {
|
||||
RWWriteMode((ref data, ref token, _)) => {
|
||||
do token.write {
|
||||
blk(data)
|
||||
blk(&mut **data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -440,12 +440,14 @@ impl<T: Const Owned> &RWWriteMode<T> {
|
|||
/// Access the pre-downgrade RWARC in write mode with a condvar.
|
||||
fn write_cond<U>(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
|
||||
match *self {
|
||||
RWWriteMode((data, ref token, ref poison)) => {
|
||||
RWWriteMode((ref data, ref token, ref poison)) => {
|
||||
do token.write_cond |cond| {
|
||||
let cvar = Condvar {
|
||||
is_mutex: false, failed: poison.failed,
|
||||
cond: cond };
|
||||
blk(data, &cvar)
|
||||
is_mutex: false,
|
||||
failed: &mut *poison.failed,
|
||||
cond: cond
|
||||
};
|
||||
blk(&mut **data, &cvar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1322,7 +1322,12 @@ mod tests {
|
|||
fn of_string2() {
|
||||
let buf = @ mut ~"1234567890";
|
||||
let mut i = 0;
|
||||
while i < 10 { *buf = *buf + *buf; i+=1;}
|
||||
while i < 10 {
|
||||
let a = *buf;
|
||||
let b = *buf;
|
||||
*buf = a + b;
|
||||
i+=1;
|
||||
}
|
||||
let sample = @*buf;
|
||||
let r = of_str(sample);
|
||||
assert char_len(r) == str::char_len(*sample);
|
||||
|
|
@ -1353,7 +1358,12 @@ mod tests {
|
|||
fn iter1() {
|
||||
let buf = @ mut ~"1234567890";
|
||||
let mut i = 0;
|
||||
while i < 10 { *buf = *buf + *buf; i+=1;}
|
||||
while i < 10 {
|
||||
let a = *buf;
|
||||
let b = *buf;
|
||||
*buf = a + b;
|
||||
i+=1;
|
||||
}
|
||||
let sample = @*buf;
|
||||
let r = of_str(sample);
|
||||
|
||||
|
|
@ -1374,7 +1384,12 @@ mod tests {
|
|||
let init = @~"1234567890";
|
||||
let buf = @mut * init;
|
||||
let mut i = 0;
|
||||
while i < 8 { *buf = *buf + *buf; i+=1;}
|
||||
while i < 8 {
|
||||
let a = *buf;
|
||||
let b = *buf;
|
||||
*buf = a + b;
|
||||
i+=1;
|
||||
}
|
||||
let sample = @*buf;
|
||||
let r1 = of_str(sample);
|
||||
let mut r2 = of_str(init);
|
||||
|
|
|
|||
|
|
@ -402,22 +402,22 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
None => Err(~"Invalid year")
|
||||
},
|
||||
'c' => {
|
||||
parse_type(s, pos, 'a', tm)
|
||||
parse_type(s, pos, 'a', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, ' '))
|
||||
.chain(|pos| parse_type(s, pos, 'b', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'b', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, ' '))
|
||||
.chain(|pos| parse_type(s, pos, 'e', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'e', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, ' '))
|
||||
.chain(|pos| parse_type(s, pos, 'T', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'T', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, ' '))
|
||||
.chain(|pos| parse_type(s, pos, 'Y', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'Y', &mut *tm))
|
||||
}
|
||||
'D' | 'x' => {
|
||||
parse_type(s, pos, 'm', tm)
|
||||
parse_type(s, pos, 'm', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, '/'))
|
||||
.chain(|pos| parse_type(s, pos, 'd', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'd', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, '/'))
|
||||
.chain(|pos| parse_type(s, pos, 'y', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'y', &mut *tm))
|
||||
}
|
||||
'd' => match match_digits(s, pos, 2u, false) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mday = v; Ok(pos) }
|
||||
|
|
@ -428,11 +428,11 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
None => Err(~"Invalid day of the month")
|
||||
},
|
||||
'F' => {
|
||||
parse_type(s, pos, 'Y', tm)
|
||||
parse_type(s, pos, 'Y', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, '-'))
|
||||
.chain(|pos| parse_type(s, pos, 'm', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'm', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, '-'))
|
||||
.chain(|pos| parse_type(s, pos, 'd', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'd', &mut *tm))
|
||||
}
|
||||
'H' => {
|
||||
// FIXME (#2350): range check.
|
||||
|
|
@ -513,18 +513,18 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
None => Err(~"Invalid hour")
|
||||
},
|
||||
'R' => {
|
||||
parse_type(s, pos, 'H', tm)
|
||||
parse_type(s, pos, 'H', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, ':'))
|
||||
.chain(|pos| parse_type(s, pos, 'M', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'M', &mut *tm))
|
||||
}
|
||||
'r' => {
|
||||
parse_type(s, pos, 'I', tm)
|
||||
parse_type(s, pos, 'I', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, ':'))
|
||||
.chain(|pos| parse_type(s, pos, 'M', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'M', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, ':'))
|
||||
.chain(|pos| parse_type(s, pos, 'S', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'S', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, ' '))
|
||||
.chain(|pos| parse_type(s, pos, 'p', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'p', &mut *tm))
|
||||
}
|
||||
'S' => {
|
||||
// FIXME (#2350): range check.
|
||||
|
|
@ -539,11 +539,11 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
}
|
||||
//'s' {}
|
||||
'T' | 'X' => {
|
||||
parse_type(s, pos, 'H', tm)
|
||||
parse_type(s, pos, 'H', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, ':'))
|
||||
.chain(|pos| parse_type(s, pos, 'M', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'M', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, ':'))
|
||||
.chain(|pos| parse_type(s, pos, 'S', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'S', &mut *tm))
|
||||
}
|
||||
't' => parse_char(s, pos, '\t'),
|
||||
'u' => {
|
||||
|
|
@ -558,11 +558,11 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
}
|
||||
}
|
||||
'v' => {
|
||||
parse_type(s, pos, 'e', tm)
|
||||
parse_type(s, pos, 'e', &mut *tm)
|
||||
.chain(|pos| parse_char(s, pos, '-'))
|
||||
.chain(|pos| parse_type(s, pos, 'b', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'b', &mut *tm))
|
||||
.chain(|pos| parse_char(s, pos, '-'))
|
||||
.chain(|pos| parse_type(s, pos, 'Y', tm))
|
||||
.chain(|pos| parse_type(s, pos, 'Y', &mut *tm))
|
||||
}
|
||||
//'W' {}
|
||||
'w' => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue