提交 159e27ae 编写于 作者: C Cameron Zwarich

Fix all violations of stronger guarantees for mutable borrows

Fix all violations in the Rust source tree of the stronger guarantee
of a unique access path for mutable borrows as described in #12624.
上级 036833ec
......@@ -406,7 +406,8 @@ unsafe fn destroy(&mut self, len: uint) {
None => {}
Some(mut next) => {
// We assume that the next chunk is completely filled.
next.destroy(next.capacity)
let capacity = next.capacity;
next.destroy(capacity)
}
}
}
......
......@@ -66,7 +66,8 @@ fn back<'a>(&'a self) -> Option<&'a T> {
/// Return a mutable reference to the last element in the RingBuf
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
if self.nelts > 0 { Some(self.get_mut(self.nelts - 1)) } else { None }
let nelts = self.nelts;
if nelts > 0 { Some(self.get_mut(nelts - 1)) } else { None }
}
/// Remove and return the first element in the RingBuf, or None if it is empty
......
......@@ -114,7 +114,8 @@ pub fn from_fn(length: uint, op: |uint| -> T) -> Vec<T> {
unsafe {
let mut xs = Vec::with_capacity(length);
while xs.len < length {
ptr::write(xs.as_mut_slice().unsafe_mut_ref(xs.len), op(xs.len));
let len = xs.len;
ptr::write(xs.as_mut_slice().unsafe_mut_ref(len), op(len));
xs.len += 1;
}
xs
......@@ -210,7 +211,8 @@ pub fn from_elem(length: uint, value: T) -> Vec<T> {
unsafe {
let mut xs = Vec::with_capacity(length);
while xs.len < length {
ptr::write(xs.as_mut_slice().unsafe_mut_ref(xs.len),
let len = xs.len;
ptr::write(xs.as_mut_slice().unsafe_mut_ref(len),
value.clone());
xs.len += 1;
}
......@@ -321,9 +323,10 @@ fn clone(&self) -> Vec<T> {
let this_slice = self.as_slice();
while vector.len < len {
unsafe {
let len = vector.len;
ptr::write(
vector.as_mut_slice().unsafe_mut_ref(vector.len),
this_slice.unsafe_ref(vector.len).clone());
vector.as_mut_slice().unsafe_mut_ref(len),
this_slice.unsafe_ref(len).clone());
}
vector.len += 1;
}
......
......@@ -127,13 +127,15 @@ pub fn new(ptr: *u8, writer: &'a mut io::Writer) -> ReprVisitor<'a> {
#[inline]
pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T| -> bool) -> bool {
unsafe {
f(self, mem::transmute::<*u8,&T>(self.ptr))
let ptr = self.ptr;
f(self, mem::transmute::<*u8,&T>(ptr))
}
}
#[inline]
pub fn visit_inner(&mut self, inner: *TyDesc) -> bool {
self.visit_ptr_inner(self.ptr, inner)
let ptr = self.ptr;
self.visit_ptr_inner(ptr, inner)
}
#[inline]
......
......@@ -637,7 +637,7 @@ fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint, rtio::SocketAddr)> {
mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t;
let dolock = || self.lock_nonblocking();
let doread = |nb| unsafe {
let n = try!(read(fd, self.read_deadline, dolock, |nb| unsafe {
let flags = if nb {c::MSG_DONTWAIT} else {0};
libc::recvfrom(fd,
buf.as_mut_ptr() as *mut libc::c_void,
......@@ -645,8 +645,7 @@ fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint, rtio::SocketAddr)> {
flags,
storagep,
&mut addrlen) as libc::c_int
};
let n = try!(read(fd, self.read_deadline, dolock, doread));
}));
sockaddr_to_addr(&storage, addrlen as uint).and_then(|addr| {
Ok((n as uint, addr))
})
......
......@@ -345,18 +345,19 @@ fn push_repeater(&mut self, c: char) -> Result<(), Error> {
}
fn push_literal(&mut self, c: char) -> Result<(), Error> {
let flags = self.flags;
match c {
'.' => {
self.push(Dot(self.flags))
self.push(Dot(flags))
}
'^' => {
self.push(Begin(self.flags))
self.push(Begin(flags))
}
'$' => {
self.push(End(self.flags))
self.push(End(flags))
}
_ => {
self.push(Literal(c, self.flags))
self.push(Literal(c, flags))
}
}
Ok(())
......
......@@ -300,12 +300,13 @@ pub fn propagate(&mut self, blk: &ast::Block) {
}
{
let words_per_id = self.words_per_id;
let mut propcx = PropagationContext {
dfcx: &mut *self,
changed: true
};
let mut temp = Vec::from_elem(self.words_per_id, 0u);
let mut temp = Vec::from_elem(words_per_id, 0u);
let mut loop_scopes = Vec::new();
while propcx.changed {
......
......@@ -547,11 +547,13 @@ struct Liveness<'a> {
impl<'a> Liveness<'a> {
fn new(ir: &'a mut IrMaps<'a>, specials: Specials) -> Liveness<'a> {
let num_live_nodes = ir.num_live_nodes;
let num_vars = ir.num_vars;
Liveness {
ir: ir,
s: specials,
successors: Vec::from_elem(ir.num_live_nodes, invalid_node()),
users: Vec::from_elem(ir.num_live_nodes * ir.num_vars, invalid_users()),
successors: Vec::from_elem(num_live_nodes, invalid_node()),
users: Vec::from_elem(num_live_nodes * num_vars, invalid_users()),
loop_scope: Vec::new(),
break_ln: NodeMap::new(),
cont_ln: NodeMap::new(),
......@@ -826,8 +828,9 @@ fn compute(&mut self, decl: &FnDecl, body: &Block) -> LiveNode {
debug!("compute: using id for block, {}", block_to_str(body));
let exit_ln = self.s.exit_ln;
let entry_ln: LiveNode =
self.with_loop_nodes(body.id, self.s.exit_ln, self.s.exit_ln,
self.with_loop_nodes(body.id, exit_ln, exit_ln,
|this| this.propagate_through_fn_block(decl, body));
// hack to skip the loop unless debug! is enabled:
......@@ -847,12 +850,13 @@ fn propagate_through_fn_block(&mut self, _: &FnDecl, blk: &Block)
-> LiveNode {
// the fallthrough exit is only for those cases where we do not
// explicitly return:
self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln);
let s = self.s;
self.init_from_succ(s.fallthrough_ln, s.exit_ln);
if blk.expr.is_none() {
self.acc(self.s.fallthrough_ln, self.s.no_ret_var, ACC_READ)
self.acc(s.fallthrough_ln, s.no_ret_var, ACC_READ)
}
self.propagate_through_block(blk, self.s.fallthrough_ln)
self.propagate_through_block(blk, s.fallthrough_ln)
}
fn propagate_through_block(&mut self, blk: &Block, succ: LiveNode)
......@@ -1036,7 +1040,8 @@ fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
ExprRet(o_e) => {
// ignore succ and subst exit_ln:
self.propagate_through_opt_expr(o_e, self.s.exit_ln)
let exit_ln = self.s.exit_ln;
self.propagate_through_opt_expr(o_e, exit_ln)
}
ExprBreak(opt_label) => {
......
......@@ -1019,9 +1019,10 @@ fn visit_item(&mut self, item: &ast::Item, _: ()) {
self.check_sane_privacy(item);
}
let in_fn = self.in_fn;
let orig_in_fn = replace(&mut self.in_fn, match item.node {
ast::ItemMod(..) => false, // modules turn privacy back on
_ => self.in_fn, // otherwise we inherit
_ => in_fn, // otherwise we inherit
});
visit::walk_item(self, item, ());
self.in_fn = orig_in_fn;
......
......@@ -202,7 +202,8 @@ fn verify_count(&mut self, c: parse::Count) {
}
parse::CountIsNextParam => {
if self.check_positional_ok() {
self.verify_arg_type(Exact(self.next_arg), Unsigned);
let next_arg = self.next_arg;
self.verify_arg_type(Exact(next_arg), Unsigned);
self.next_arg += 1;
}
}
......
......@@ -73,7 +73,8 @@ fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute {
let style = if self.eat(&token::NOT) {
if !permit_inner {
self.span_err(self.span,
let span = self.span;
self.span_err(span,
"an inner attribute is not permitted in \
this context");
}
......
......@@ -368,7 +368,8 @@ fn consume_block_comment(&mut self) -> Option<TokenAndSpan> {
} else {
"unterminated block comment"
};
self.fatal_span(start_bpos, self.last_pos, msg);
let last_bpos = self.last_pos;
self.fatal_span(start_bpos, last_bpos, msg);
} else if self.curr_is('/') && self.nextch_is('*') {
level += 1;
self.bump();
......@@ -419,7 +420,8 @@ fn scan_exponent(&mut self, start_bpos: BytePos) -> Option<String> {
rslt.push_str(exponent.as_slice());
return Some(rslt);
} else {
self.err_span(start_bpos, self.last_pos, "scan_exponent: bad fp literal");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "scan_exponent: bad fp literal");
rslt.push_str("1"); // arbitrary placeholder exponent
return Some(rslt);
}
......@@ -506,14 +508,16 @@ enum Result { Signed(ast::IntTy), Unsigned(ast::UintTy) }
else { Unsigned(ast::TyU64) };
}
if num_str.len() == 0u {
self.err_span(start_bpos, self.last_pos, "no valid digits found for number");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "no valid digits found for number");
num_str = "1".to_string();
}
let parsed = match from_str_radix::<u64>(num_str.as_slice(),
base as uint) {
Some(p) => p,
None => {
self.err_span(start_bpos, self.last_pos, "int literal is too large");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "int literal is too large");
1
}
};
......@@ -546,13 +550,15 @@ enum Result { Signed(ast::IntTy), Unsigned(ast::UintTy) }
if c == '3' && n == '2' {
self.bump();
self.bump();
self.check_float_base(start_bpos, self.last_pos, base);
let last_bpos = self.last_pos;
self.check_float_base(start_bpos, last_bpos, base);
return token::LIT_FLOAT(str_to_ident(num_str.as_slice()),
ast::TyF32);
} else if c == '6' && n == '4' {
self.bump();
self.bump();
self.check_float_base(start_bpos, self.last_pos, base);
let last_bpos = self.last_pos;
self.check_float_base(start_bpos, last_bpos, base);
return token::LIT_FLOAT(str_to_ident(num_str.as_slice()),
ast::TyF64);
/* FIXME (#2252): if this is out of range for either a
......@@ -562,25 +568,30 @@ enum Result { Signed(ast::IntTy), Unsigned(ast::UintTy) }
self.bump();
self.bump();
self.bump();
self.check_float_base(start_bpos, self.last_pos, base);
let last_bpos = self.last_pos;
self.check_float_base(start_bpos, last_bpos, base);
return token::LIT_FLOAT(str_to_ident(num_str.as_slice()), ast::TyF128);
}
self.err_span(start_bpos, self.last_pos, "expected `f32`, `f64` or `f128` suffix");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "expected `f32`, `f64` or `f128` suffix");
}
if is_float {
self.check_float_base(start_bpos, self.last_pos, base);
let last_bpos = self.last_pos;
self.check_float_base(start_bpos, last_bpos, base);
return token::LIT_FLOAT_UNSUFFIXED(str_to_ident(
num_str.as_slice()));
} else {
if num_str.len() == 0u {
self.err_span(start_bpos, self.last_pos, "no valid digits found for number");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "no valid digits found for number");
num_str = "1".to_string();
}
let parsed = match from_str_radix::<u64>(num_str.as_slice(),
base as uint) {
Some(p) => p,
None => {
self.err_span(start_bpos, self.last_pos, "int literal is too large");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "int literal is too large");
1
}
};
......@@ -597,10 +608,12 @@ fn scan_numeric_escape(&mut self, n_hex_digits: uint, delim: char) -> char {
let start_bpos = self.last_pos;
for _ in range(0, n_hex_digits) {
if self.is_eof() {
self.fatal_span(start_bpos, self.last_pos, "unterminated numeric character escape");
let last_bpos = self.last_pos;
self.fatal_span(start_bpos, last_bpos, "unterminated numeric character escape");
}
if self.curr_is(delim) {
self.err_span(start_bpos, self.last_pos, "numeric character escape is too short");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "numeric character escape is too short");
break;
}
let c = self.curr.unwrap_or('\x00');
......@@ -616,7 +629,8 @@ fn scan_numeric_escape(&mut self, n_hex_digits: uint, delim: char) -> char {
match char::from_u32(accum_int) {
Some(x) => x,
None => {
self.err_span(start_bpos, self.last_pos, "illegal numeric character escape");
let last_bpos = self.last_pos;
self.err_span(start_bpos, last_bpos, "illegal numeric character escape");
'?'
}
}
......@@ -773,17 +787,18 @@ fn next_token_inner(&mut self) -> token::Token {
});
let keyword_checking_token =
&token::IDENT(keyword_checking_ident, false);
let last_bpos = self.last_pos;
if token::is_keyword(token::keywords::Self,
keyword_checking_token) {
self.err_span(start,
self.last_pos,
last_bpos,
"invalid lifetime name: 'self \
is no longer a special lifetime");
} else if token::is_any_keyword(keyword_checking_token) &&
!token::is_keyword(token::keywords::Static,
keyword_checking_token) {
self.err_span(start,
self.last_pos,
last_bpos,
"invalid lifetime name");
}
return token::LIFETIME(ident);
......@@ -811,7 +826,8 @@ fn next_token_inner(&mut self) -> token::Token {
'u' => self.scan_numeric_escape(4u, '\''),
'U' => self.scan_numeric_escape(8u, '\''),
c2 => {
self.err_span_char(escaped_pos, self.last_pos,
let last_bpos = self.last_pos;
self.err_span_char(escaped_pos, last_bpos,
"unknown character escape", c2);
c2
}
......@@ -820,17 +836,19 @@ fn next_token_inner(&mut self) -> token::Token {
}
}
'\t' | '\n' | '\r' | '\'' => {
self.err_span_char( start, self.last_pos,
let last_bpos = self.last_pos;
self.err_span_char( start, last_bpos,
"character constant must be escaped", c2);
}
_ => {}
}
if !self.curr_is('\'') {
let last_bpos = self.last_pos;
self.fatal_span_verbose(
// Byte offsetting here is okay because the
// character before position `start` is an
// ascii single quote.
start - BytePos(1), self.last_pos,
start - BytePos(1), last_bpos,
"unterminated character constant".to_string());
}
self.bump(); // advance curr past token
......@@ -842,7 +860,8 @@ fn next_token_inner(&mut self) -> token::Token {
self.bump();
while !self.curr_is('"') {
if self.is_eof() {
self.fatal_span(start_bpos, self.last_pos, "unterminated double quote string");
let last_bpos = self.last_pos;
self.fatal_span(start_bpos, last_bpos, "unterminated double quote string");
}
let ch = self.curr.unwrap();
......@@ -850,7 +869,8 @@ fn next_token_inner(&mut self) -> token::Token {
match ch {
'\\' => {
if self.is_eof() {
self.fatal_span(start_bpos, self.last_pos,
let last_bpos = self.last_pos;
self.fatal_span(start_bpos, last_bpos,
"unterminated double quote string");
}
......@@ -876,7 +896,8 @@ fn next_token_inner(&mut self) -> token::Token {
accum_str.push_char(self.scan_numeric_escape(8u, '"'));
}
c2 => {
self.err_span_char(escaped_pos, self.last_pos,
let last_bpos = self.last_pos;
self.err_span_char(escaped_pos, last_bpos,
"unknown string escape", c2);
}
}
......@@ -897,19 +918,23 @@ fn next_token_inner(&mut self) -> token::Token {
}
if self.is_eof() {
self.fatal_span(start_bpos, self.last_pos, "unterminated raw string");
let last_bpos = self.last_pos;
self.fatal_span(start_bpos, last_bpos, "unterminated raw string");
} else if !self.curr_is('"') {
self.fatal_span_char(start_bpos, self.last_pos,
let last_bpos = self.last_pos;
let curr_char = self.curr.unwrap();
self.fatal_span_char(start_bpos, last_bpos,
"only `#` is allowed in raw string delimitation; \
found illegal character",
self.curr.unwrap());
curr_char);
}
self.bump();
let content_start_bpos = self.last_pos;
let mut content_end_bpos;
'outer: loop {
if self.is_eof() {
self.fatal_span(start_bpos, self.last_pos, "unterminated raw string");
let last_bpos = self.last_pos;
self.fatal_span(start_bpos, last_bpos, "unterminated raw string");
}
if self.curr_is('"') {
content_end_bpos = self.last_pos;
......@@ -956,8 +981,9 @@ fn next_token_inner(&mut self) -> token::Token {
'^' => { return self.binop(token::CARET); }
'%' => { return self.binop(token::PERCENT); }
c => {
self.fatal_span_char(self.last_pos, self.pos,
"unknown start of token", c);
let last_bpos = self.last_pos;
let bpos = self.pos;
self.fatal_span_char(last_bpos, bpos, "unknown start of token", c);
}
}
}
......
此差异已折叠。
......@@ -322,7 +322,8 @@ pub fn pretty_print(&mut self, t: Token) -> io::IoResult<()> {
b.offset, self.left, self.right);
*self.token.get_mut(self.right) = t;
*self.size.get_mut(self.right) = -self.right_total;
self.scan_push(self.right);
let right = self.right;
self.scan_push(right);
Ok(())
}
End => {
......@@ -334,7 +335,8 @@ pub fn pretty_print(&mut self, t: Token) -> io::IoResult<()> {
self.advance_right();
*self.token.get_mut(self.right) = t;
*self.size.get_mut(self.right) = -1;
self.scan_push(self.right);
let right = self.right;
self.scan_push(right);
Ok(())
}
}
......@@ -348,7 +350,8 @@ pub fn pretty_print(&mut self, t: Token) -> io::IoResult<()> {
debug!("pp Break({})/buffer ~[{},{}]",
b.offset, self.left, self.right);
self.check_stack(0);
self.scan_push(self.right);
let right = self.right;
self.scan_push(right);
*self.token.get_mut(self.right) = t;
*self.size.get_mut(self.right) = -self.right_total;
self.right_total += b.blank_space;
......
......@@ -347,7 +347,8 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), *flags);
if res.is_err() { return res }
output.push_all(res.unwrap().as_slice());
old_state = state; // will cause state to go to Nothing
// will cause state to go to Nothing
old_state = FormatPattern(*flags, *fstate);
} else { return Err("stack is empty".to_string()) },
(FormatStateFlags,'#') => {
flags.alternate = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册