Skip to content

Commit

Permalink
auto merge of #18459 : alexcrichton/rust/rollup, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Oct 31, 2014
2 parents a12d06b + 6fcba88 commit 221fc1e
Show file tree
Hide file tree
Showing 257 changed files with 1,170 additions and 1,439 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Expand Up @@ -1013,7 +1013,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
if prefix_matches(line, prefixes[i].as_slice()) &&
line.contains(ee.kind.as_slice()) &&
line.contains(ee.msg.as_slice()) {
*found_flags.get_mut(i) = true;
found_flags[i] = true;
was_expected = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/complement-bugreport.md
Expand Up @@ -47,7 +47,7 @@ release: 0.12.0
```

Finally, if you can run the offending command under gdb, pasting a stack trace can be
useful; to do so, you will need to set a breakpoint on `rust_fail`.
useful; to do so, you will need to set a breakpoint on `rust_panic`.

# I submitted a bug, but nobody has commented on it!

Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-lifetimes.md
Expand Up @@ -56,7 +56,7 @@ a reference.
fn compute_distance(p1: &Point, p2: &Point) -> f64 {
let x_d = p1.x - p2.x;
let y_d = p1.y - p2.y;
sqrt(x_d * x_d + y_d * y_d)
(x_d * x_d + y_d * y_d).sqrt()
}
~~~

Expand Down
7 changes: 5 additions & 2 deletions src/doc/reference.md
Expand Up @@ -1153,7 +1153,7 @@ exposing an API making it possible for it to occur in safe code.

* Data races
* Dereferencing a null/dangling raw pointer
* Mutating an immutable value/reference
* Mutating an immutable value/reference without `UnsafeCell`
* Reads of [undef](http://llvm.org/docs/LangRef.html#undefined-values)
(uninitialized) memory
* Breaking the [pointer aliasing
Expand All @@ -1166,11 +1166,14 @@ exposing an API making it possible for it to occur in safe code.
* Using `std::ptr::copy_nonoverlapping_memory` (`memcpy32`/`memcpy64`
instrinsics) on overlapping buffers
* Invalid values in primitive types, even in private fields/locals:
* Dangling/null pointers in non-raw pointers, or slices
* Dangling/null references or boxes
* A value other than `false` (0) or `true` (1) in a `bool`
* A discriminant in an `enum` not included in the type definition
* A value in a `char` which is a surrogate or above `char::MAX`
* non-UTF-8 byte sequences in a `str`
* Unwinding into Rust from foreign code or unwinding from Rust into foreign
code. Rust's failure system is not compatible with exception handling in
other languages. Unwinding must be caught and handled at FFI boundaries.

##### Behaviour not considered unsafe

Expand Down
12 changes: 6 additions & 6 deletions src/grammar/verify.rs
Expand Up @@ -59,20 +59,20 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
"FLOAT_SUFFIX" => id(),
"INT_SUFFIX" => id(),
"SHL" => token::BinOp(token::Shl),
"LBRACE" => token::LBrace,
"LBRACE" => token::OpenDelim(token::Brace),
"RARROW" => token::Rarrow,
"LIT_STR" => token::LitStr(Name(0)),
"DOTDOT" => token::DotDot,
"MOD_SEP" => token::ModSep,
"DOTDOTDOT" => token::DotDotDot,
"NOT" => token::Not,
"AND" => token::BinOp(token::And),
"LPAREN" => token::LParen,
"LPAREN" => token::OpenDelim(token::Paren),
"ANDAND" => token::AndAnd,
"AT" => token::At,
"LBRACKET" => token::LBracket,
"LBRACKET" => token::OpenDelim(token::Bracket),
"LIT_STR_RAW" => token::LitStrRaw(Name(0), 0),
"RPAREN" => token::RParen,
"RPAREN" => token::CloseDelim(token::Paren),
"SLASH" => token::BinOp(token::Slash),
"COMMA" => token::Comma,
"LIFETIME" => token::Lifetime(ast::Ident { name: Name(0), ctxt: 0 }),
Expand All @@ -83,15 +83,15 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
"LIT_CHAR" => token::LitChar(Name(0)),
"LIT_BYTE" => token::LitByte(Name(0)),
"EQ" => token::Eq,
"RBRACKET" => token::RBracket,
"RBRACKET" => token::CloseDelim(token::Bracket),
"COMMENT" => token::Comment,
"DOC_COMMENT" => token::DocComment(Name(0)),
"DOT" => token::Dot,
"EQEQ" => token::EqEq,
"NE" => token::Ne,
"GE" => token::Ge,
"PERCENT" => token::BinOp(token::Percent),
"RBRACE" => token::RBrace,
"RBRACE" => token::CloseDelim(token::Brace),
"BINOP" => token::BinOp(token::Plus),
"POUND" => token::Pound,
"OROR" => token::OrOr,
Expand Down
16 changes: 8 additions & 8 deletions src/libarena/lib.rs
Expand Up @@ -29,7 +29,7 @@
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![feature(unsafe_destructor)]
#![allow(missing_doc)]
#![allow(missing_docs)]

use std::cell::{Cell, RefCell};
use std::cmp;
Expand Down Expand Up @@ -208,13 +208,13 @@ impl Arena {
}

#[inline]
fn alloc_copy<T>(&self, op: || -> T) -> &T {
fn alloc_copy<T>(&self, op: || -> T) -> &mut T {
unsafe {
let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
mem::min_align_of::<T>());
let ptr = ptr as *mut T;
ptr::write(&mut (*ptr), op());
return &*ptr;
return &mut *ptr;
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ impl Arena {
}

#[inline]
fn alloc_noncopy<T>(&self, op: || -> T) -> &T {
fn alloc_noncopy<T>(&self, op: || -> T) -> &mut T {
unsafe {
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
Expand All @@ -279,14 +279,14 @@ impl Arena {
// the object is there.
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);

return &*ptr;
return &mut *ptr;
}
}

/// Allocates a new item in the arena, using `op` to initialize the value,
/// and returns a reference to it.
#[inline]
pub fn alloc<T>(&self, op: || -> T) -> &T {
pub fn alloc<T>(&self, op: || -> T) -> &mut T {
unsafe {
if intrinsics::needs_drop::<T>() {
self.alloc_noncopy(op)
Expand Down Expand Up @@ -458,12 +458,12 @@ impl<T> TypedArena<T> {

/// Allocates an object in the `TypedArena`, returning a reference to it.
#[inline]
pub fn alloc(&self, object: T) -> &T {
pub fn alloc(&self, object: T) -> &mut T {
if self.ptr == self.end {
self.grow()
}

let ptr: &T = unsafe {
let ptr: &mut T = unsafe {
let ptr: &mut T = mem::transmute(self.ptr);
ptr::write(ptr, object);
self.ptr.set(self.ptr.get().offset(1));
Expand Down
21 changes: 11 additions & 10 deletions src/libcollections/bitv.rs
Expand Up @@ -243,7 +243,7 @@ impl Bitv {
let used_bits = bitv.nbits % u32::BITS;
if init && used_bits != 0 {
let largest_used_word = (bitv.nbits + u32::BITS - 1) / u32::BITS - 1;
*bitv.storage.get_mut(largest_used_word) &= (1 << used_bits) - 1;
bitv.storage[largest_used_word] &= (1 << used_bits) - 1;
}

bitv
Expand Down Expand Up @@ -297,8 +297,9 @@ impl Bitv {
let w = i / u32::BITS;
let b = i % u32::BITS;
let flag = 1 << b;
*self.storage.get_mut(w) = if x { self.storage[w] | flag }
else { self.storage[w] & !flag };
let val = if x { self.storage[w] | flag }
else { self.storage[w] & !flag };
self.storage[w] = val;
}

/// Sets all bits to 1.
Expand Down Expand Up @@ -617,7 +618,7 @@ impl Bitv {
self.storage.truncate(word_len);
if len % u32::BITS > 0 {
let mask = (1 << len % u32::BITS) - 1;
*self.storage.get_mut(word_len - 1) &= mask;
self.storage[word_len - 1] &= mask;
}
}
}
Expand Down Expand Up @@ -681,15 +682,15 @@ impl Bitv {
let overhang = self.nbits % u32::BITS; // # of already-used bits
let mask = !((1 << overhang) - 1); // e.g. 5 unused bits => 111110....0
if value {
*self.storage.get_mut(old_last_word) |= mask;
self.storage[old_last_word] |= mask;
} else {
*self.storage.get_mut(old_last_word) &= !mask;
self.storage[old_last_word] &= !mask;
}
}
// Fill in words after the old tail word
let stop_idx = cmp::min(self.storage.len(), new_nwords);
for idx in range(old_last_word + 1, stop_idx) {
*self.storage.get_mut(idx) = full_value;
self.storage[idx] = full_value;
}
// Allocate new words, if needed
if new_nwords > self.storage.len() {
Expand All @@ -700,7 +701,7 @@ impl Bitv {
if value {
let tail_word = new_nwords - 1;
let used_bits = new_nbits % u32::BITS;
*self.storage.get_mut(tail_word) &= (1 << used_bits) - 1;
self.storage[tail_word] &= (1 << used_bits) - 1;
}
}
// Adjust internal bit count
Expand Down Expand Up @@ -728,7 +729,7 @@ impl Bitv {
let ret = self.get(self.nbits - 1);
// If we are unusing a whole word, make sure it is zeroed out
if self.nbits % u32::BITS == 1 {
*self.storage.get_mut(self.nbits / u32::BITS) = 0;
self.storage[self.nbits / u32::BITS] = 0;
}
self.nbits -= 1;
ret
Expand Down Expand Up @@ -1184,7 +1185,7 @@ impl BitvSet {
for (i, w) in other_words {
let old = self_bitv.storage[i];
let new = f(old, w);
*self_bitv.storage.get_mut(i) = new;
self_bitv.storage[i] = new;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/btree/map.rs
Expand Up @@ -690,6 +690,12 @@ impl<K: Ord, V> Index<K, V> for BTreeMap<K, V> {
}
}

impl<K: Ord, V> IndexMut<K, V> for BTreeMap<K, V> {
fn index_mut(&mut self, key: &K) -> &mut V {
self.find_mut(key).expect("no entry found for key")
}
}

/// Genericises over how to get the correct type of iterator from the correct type
/// of Node ownership.
trait Traverse<N> {
Expand Down
28 changes: 14 additions & 14 deletions src/libcollections/priority_queue.rs
Expand Up @@ -71,7 +71,7 @@
//! let mut pq = PriorityQueue::new();
//!
//! // We're at `start`, with a zero cost
//! *dist.get_mut(start) = 0u;
//! dist[start] = 0u;
//! pq.push(State { cost: 0u, position: start });
//!
//! // Examine the frontier with lower cost nodes first (min-heap)
Expand All @@ -96,7 +96,7 @@
//! if next.cost < dist[next.position] {
//! pq.push(next);
//! // Relaxation, we have now found a better way
//! *dist.get_mut(next.position) = next.cost;
//! dist[next.position] = next.cost;
//! }
//! }
//! }
Expand Down Expand Up @@ -151,7 +151,7 @@
//! }
//! ```

#![allow(missing_doc)]
#![allow(missing_docs)]

use core::prelude::*;

Expand Down Expand Up @@ -330,7 +330,7 @@ impl<T: Ord> PriorityQueue<T> {
None => { None }
Some(mut item) => {
if !self.is_empty() {
swap(&mut item, self.data.get_mut(0));
swap(&mut item, &mut self.data[0]);
self.siftdown(0);
}
Some(item)
Expand Down Expand Up @@ -378,7 +378,7 @@ impl<T: Ord> PriorityQueue<T> {
/// ```
pub fn push_pop(&mut self, mut item: T) -> T {
if !self.is_empty() && *self.top().unwrap() > item {
swap(&mut item, self.data.get_mut(0));
swap(&mut item, &mut self.data[0]);
self.siftdown(0);
}
item
Expand All @@ -402,7 +402,7 @@ impl<T: Ord> PriorityQueue<T> {
/// ```
pub fn replace(&mut self, mut item: T) -> Option<T> {
if !self.is_empty() {
swap(&mut item, self.data.get_mut(0));
swap(&mut item, &mut self.data[0]);
self.siftdown(0);
Some(item)
} else {
Expand Down Expand Up @@ -462,40 +462,40 @@ impl<T: Ord> PriorityQueue<T> {
// compared to using swaps, which involves twice as many moves.
fn siftup(&mut self, start: uint, mut pos: uint) {
unsafe {
let new = replace(self.data.get_mut(pos), zeroed());
let new = replace(&mut self.data[pos], zeroed());

while pos > start {
let parent = (pos - 1) >> 1;
if new > self.data[parent] {
let x = replace(self.data.get_mut(parent), zeroed());
ptr::write(self.data.get_mut(pos), x);
let x = replace(&mut self.data[parent], zeroed());
ptr::write(&mut self.data[pos], x);
pos = parent;
continue
}
break
}
ptr::write(self.data.get_mut(pos), new);
ptr::write(&mut self.data[pos], new);
}
}

fn siftdown_range(&mut self, mut pos: uint, end: uint) {
unsafe {
let start = pos;
let new = replace(self.data.get_mut(pos), zeroed());
let new = replace(&mut self.data[pos], zeroed());

let mut child = 2 * pos + 1;
while child < end {
let right = child + 1;
if right < end && !(self.data[child] > self.data[right]) {
child = right;
}
let x = replace(self.data.get_mut(child), zeroed());
ptr::write(self.data.get_mut(pos), x);
let x = replace(&mut self.data[child], zeroed());
ptr::write(&mut self.data[pos], x);
pos = child;
child = 2 * pos + 1;
}

ptr::write(self.data.get_mut(pos), new);
ptr::write(&mut self.data[pos], new);
self.siftup(start, pos);
}
}
Expand Down

0 comments on commit 221fc1e

Please sign in to comment.