Skip to content

Commit

Permalink
auto merge of #19508 : cmr/rust/rollup-2014_12_03, r=cmr
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Dec 5, 2014
2 parents 95d1771 + 33f34bd commit 6f4c11b
Show file tree
Hide file tree
Showing 133 changed files with 3,710 additions and 3,658 deletions.
28 changes: 14 additions & 14 deletions src/doc/guide.md
Expand Up @@ -140,7 +140,7 @@ $ editor main.rs
```

Rust files always end in a `.rs` extension. If you're using more than one word
in your file name, use an underscore. `hello_world.rs` rather than
in your filename, use an underscore. `hello_world.rs` rather than
`helloworld.rs`.

Now that you've got your file open, type this in:
Expand Down Expand Up @@ -200,7 +200,7 @@ about this difference. Just know that sometimes, you'll see a `!`, and that
means that you're calling a macro instead of a normal function. Rust implements
`println!` as a macro rather than a function for good reasons, but that's a
very advanced topic. You'll learn more when we talk about macros later. One
last thing to mention: Rust's macros are significantly different than C macros,
last thing to mention: Rust's macros are significantly different from C macros,
if you've used those. Don't be scared of using macros. We'll get to the details
eventually, you'll just have to trust us for now.

Expand Down Expand Up @@ -595,8 +595,8 @@ let y = if x == 5i { 10i } else { 15i };
```

This reveals two interesting things about Rust: it is an expression-based
language, and semicolons are different than in other 'curly brace and
semicolon'-based languages. These two things are related.
language, and semicolons are different from semicolons in other 'curly brace
and semicolon'-based languages. These two things are related.

## Expressions vs. Statements

Expand Down Expand Up @@ -1454,7 +1454,7 @@ Both `continue` and `break` are valid in both kinds of loops.
# Strings

Strings are an important concept for any programmer to master. Rust's string
handling system is a bit different than in other languages, due to its systems
handling system is a bit different from other languages, due to its systems
focus. Any time you have a data structure of variable size, things can get
tricky, and strings are a re-sizable data structure. That said, Rust's strings
also work differently than in some other systems languages, such as C.
Expand Down Expand Up @@ -2064,8 +2064,8 @@ Great! Next up: let's compare our guess to the secret guess.
## Comparing guesses

If you remember, earlier in the guide, we made a `cmp` function that compared
two numbers. Let's add that in, along with a `match` statement to compare the
guess to the secret guess:
two numbers. Let's add that in, along with a `match` statement to compare our
guess to the secret number:

```{rust,ignore}
use std::io;
Expand Down Expand Up @@ -2861,7 +2861,7 @@ parts of your library. The six levels are:
* experimental: This item was only recently introduced or is otherwise in a
state of flux. It may change significantly, or even be removed. No guarantee
of backwards-compatibility.
* unstable: This item is still under development, but requires more testing to
* unstable: This item is still under development and requires more testing to
be considered stable. No guarantee of backwards-compatibility.
* stable: This item is considered stable, and will not change significantly.
Guarantee of backwards-compatibility.
Expand Down Expand Up @@ -5174,12 +5174,12 @@ processor. Rust's semantics lend themselves very nicely to solving a number of
issues that programmers have with concurrency. Many concurrency errors that are
runtime errors in other languages are compile-time errors in Rust.

Rust's concurrency primitive is called a **task**. Tasks are lightweight, and
do not share memory in an unsafe manner, preferring message passing to
communicate. It's worth noting that tasks are implemented as a library, and
not part of the language. This means that in the future, other concurrency
libraries can be written for Rust to help in specific scenarios. Here's an
example of creating a task:
Rust's concurrency primitive is called a **task**. Tasks are similar to
threads, and do not share memory in an unsafe manner, preferring message
passing to communicate. It's worth noting that tasks are implemented as a
library, and not part of the language. This means that in the future, other
concurrency libraries can be written for Rust to help in specific scenarios.
Here's an example of creating a task:

```{rust}
spawn(proc() {
Expand Down
2 changes: 1 addition & 1 deletion src/doc/reference.md
Expand Up @@ -522,7 +522,7 @@ The two values of the boolean type are written `true` and `false`.
### Symbols

```{.ebnf .gram}
symbol : "::" "->"
symbol : "::" | "->"
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
| ',' | ';' ;
```
Expand Down
16 changes: 11 additions & 5 deletions src/etc/gdb_rust_pretty_printing.py
Expand Up @@ -54,21 +54,27 @@ def rust_pretty_printer_lookup_function(val):
return RustStructPrinter(val, false)

if enum_member_count == 1:
if enum_members[0].name == None:
first_variant_name = enum_members[0].name
if first_variant_name == None:
# This is a singleton enum
return rust_pretty_printer_lookup_function(val[enum_members[0]])
else:
assert enum_members[0].name.startswith("RUST$ENCODED$ENUM$")
assert first_variant_name.startswith("RUST$ENCODED$ENUM$")
# This is a space-optimized enum
last_separator_index = enum_members[0].name.rfind("$")
last_separator_index = first_variant_name.rfind("$")
second_last_separator_index = first_variant_name.rfind("$", 0, last_separator_index)
disr_field_index = first_variant_name[second_last_separator_index + 1 :
last_separator_index]
disr_field_index = int(disr_field_index)

sole_variant_val = val[enum_members[0]]
disr_field = get_field_at_index(sole_variant_val, disr_field_index)
discriminant = int(sole_variant_val[disr_field])
discriminant = sole_variant_val[disr_field]

# If the discriminant field is a fat pointer we have to consider the
# first word as the true discriminant
if discriminant.type.code == gdb.TYPE_CODE_STRUCT:
discriminant = discriminant[get_field_at_index(discriminant, 0)]

if discriminant == 0:
null_variant_name = first_variant_name[last_separator_index + 1:]
Expand Down Expand Up @@ -173,7 +179,7 @@ def to_string(self):

class IdentityPrinter:
def __init__(self, string):
self.string
self.string = string

def to_string(self):
return self.string
Expand Down
5 changes: 2 additions & 3 deletions src/etc/licenseck.py
Expand Up @@ -38,9 +38,8 @@
"rt/isaac/randport.cpp", # public domain
"rt/isaac/rand.h", # public domain
"rt/isaac/standard.h", # public domain
"libstd/sync/mpsc_queue.rs", # BSD
"libstd/sync/spsc_queue.rs", # BSD
"libstd/sync/mpmc_bounded_queue.rs", # BSD
"libstd/comm/mpsc_queue.rs", # BSD
"libstd/comm/spsc_queue.rs", # BSD
"test/bench/shootout-binarytrees.rs", # BSD
"test/bench/shootout-chameneos-redux.rs", # BSD
"test/bench/shootout-fannkuch-redux.rs", # BSD
Expand Down
9 changes: 7 additions & 2 deletions src/etc/lldb_rust_formatters.py
Expand Up @@ -138,9 +138,14 @@ def print_enum_val(val, internal_dict):
return "<invalid enum encoding: %s>" % first_variant_name

# Read the discriminant
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index)

if disr_val == 0:
# If the discriminant field is a fat pointer we have to consider the
# first word as the true discriminant
if disr_val.GetType().GetTypeClass() == lldb.eTypeClassStruct:
disr_val = disr_val.GetChildAtIndex(0)

if disr_val.GetValueAsUnsigned() == 0:
# Null case: Print the name of the null-variant
null_variant_name = first_variant_name[last_separator_index + 1:]
return null_variant_name
Expand Down
58 changes: 55 additions & 3 deletions src/liballoc/heap.rs
Expand Up @@ -123,7 +123,59 @@ const MIN_ALIGN: uint = 8;
target_arch = "x86_64"))]
const MIN_ALIGN: uint = 16;

#[cfg(jemalloc)]
#[cfg(external_funcs)]
mod imp {
extern {
fn rust_allocate(size: uint, align: uint) -> *mut u8;
fn rust_deallocate(ptr: *mut u8, old_size: uint, align: uint);
fn rust_reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint) -> *mut u8;
fn rust_reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
align: uint) -> uint;
fn rust_usable_size(size: uint, align: uint) -> uint;
fn rust_stats_print();
}

#[inline]
pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 {
rust_allocate(size, align)
}

#[inline]
pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
align: uint) -> uint {
rust_reallocate_inplace(ptr, old_size, size, align)
}

#[inline]
pub unsafe fn deallocate(ptr: *mut u8, old_size: uint, align: uint) {
rust_deallocate(ptr, old_size, align)
}

#[inline]
pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
align: uint) -> uint {
rust_reallocate_inplace(ptr, old_size, size, align)
}

#[inline]
pub fn usable_size(size: uint, align: uint) -> uint {
unsafe { rust_usable_size(size, align) }
}

#[inline]
pub fn stats_print() {
unsafe { rust_stats_print() }
}
}

#[cfg(external_crate)]
mod imp {
extern crate external;
pub use self::external::{allocate, deallocate, reallocate_inplace, reallocate};
pub use self::external::{usable_size, stats_print};
}

#[cfg(all(not(external_funcs), not(external_crate), jemalloc))]
mod imp {
use core::option::{None, Option};
use core::ptr::{null_mut, null};
Expand Down Expand Up @@ -199,7 +251,7 @@ mod imp {
}
}

#[cfg(all(not(jemalloc), unix))]
#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), unix))]
mod imp {
use core::cmp;
use core::ptr;
Expand Down Expand Up @@ -260,7 +312,7 @@ mod imp {
pub fn stats_print() {}
}

#[cfg(all(not(jemalloc), windows))]
#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), windows))]
mod imp {
use libc::{c_void, size_t};
use libc;
Expand Down
126 changes: 125 additions & 1 deletion src/libcollections/trie/set.rs
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

// FIXME(conventions): implement bounded iterators
// FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub
// FIXME(conventions): replace each_reverse by making iter DoubleEnded
// FIXME(conventions): implement iter_mut and into_iter

Expand Down Expand Up @@ -463,6 +462,90 @@ impl Extend<uint> for TrieSet {
}
}

#[unstable = "matches collection reform specification, waiting for dust to settle"]
impl BitOr<TrieSet, TrieSet> for TrieSet {
/// Returns the union of `self` and `rhs` as a new `TrieSet`.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
///
/// let set: TrieSet = a | b;
/// let v: Vec<uint> = set.iter().collect();
/// assert_eq!(v, vec![1u, 2, 3, 4, 5]);
/// ```
fn bitor(&self, rhs: &TrieSet) -> TrieSet {
self.union(rhs).collect()
}
}

#[unstable = "matches collection reform specification, waiting for dust to settle"]
impl BitAnd<TrieSet, TrieSet> for TrieSet {
/// Returns the intersection of `self` and `rhs` as a new `TrieSet`.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
/// let b: TrieSet = vec![2, 3, 4].into_iter().collect();
///
/// let set: TrieSet = a & b;
/// let v: Vec<uint> = set.iter().collect();
/// assert_eq!(v, vec![2u, 3]);
/// ```
fn bitand(&self, rhs: &TrieSet) -> TrieSet {
self.intersection(rhs).collect()
}
}

#[unstable = "matches collection reform specification, waiting for dust to settle"]
impl BitXor<TrieSet, TrieSet> for TrieSet {
/// Returns the symmetric difference of `self` and `rhs` as a new `TrieSet`.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
///
/// let set: TrieSet = a ^ b;
/// let v: Vec<uint> = set.iter().collect();
/// assert_eq!(v, vec![1u, 2, 4, 5]);
/// ```
fn bitxor(&self, rhs: &TrieSet) -> TrieSet {
self.symmetric_difference(rhs).collect()
}
}

#[unstable = "matches collection reform specification, waiting for dust to settle"]
impl Sub<TrieSet, TrieSet> for TrieSet {
/// Returns the difference of `self` and `rhs` as a new `TrieSet`.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
///
/// let set: TrieSet = a - b;
/// let v: Vec<uint> = set.iter().collect();
/// assert_eq!(v, vec![1u, 2]);
/// ```
fn sub(&self, rhs: &TrieSet) -> TrieSet {
self.difference(rhs).collect()
}
}

/// A forward iterator over a set.
pub struct SetItems<'a> {
iter: Entries<'a, ()>
Expand Down Expand Up @@ -569,6 +652,7 @@ impl<'a> Iterator<uint> for UnionItems<'a> {
mod test {
use std::prelude::*;
use std::uint;
use vec::Vec;

use super::TrieSet;

Expand Down Expand Up @@ -738,4 +822,44 @@ mod test {
&[1, 5, 9, 13, 19],
&[1, 3, 5, 9, 11, 13, 16, 19, 24]);
}

#[test]
fn test_bit_or() {
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
let b: TrieSet = vec![3, 4, 5].into_iter().collect();

let set: TrieSet = a | b;
let v: Vec<uint> = set.iter().collect();
assert_eq!(v, vec![1u, 2, 3, 4, 5]);
}

#[test]
fn test_bit_and() {
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
let b: TrieSet = vec![2, 3, 4].into_iter().collect();

let set: TrieSet = a & b;
let v: Vec<uint> = set.iter().collect();
assert_eq!(v, vec![2u, 3]);
}

#[test]
fn test_bit_xor() {
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
let b: TrieSet = vec![3, 4, 5].into_iter().collect();

let set: TrieSet = a ^ b;
let v: Vec<uint> = set.iter().collect();
assert_eq!(v, vec![1u, 2, 4, 5]);
}

#[test]
fn test_sub() {
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
let b: TrieSet = vec![3, 4, 5].into_iter().collect();

let set: TrieSet = a - b;
let v: Vec<uint> = set.iter().collect();
assert_eq!(v, vec![1u, 2]);
}
}

0 comments on commit 6f4c11b

Please sign in to comment.