Skip to content

Commit 6f4c11b

Browse files
committed
auto merge of #19508 : cmr/rust/rollup-2014_12_03, r=cmr
2 parents 95d1771 + 33f34bd commit 6f4c11b

File tree

133 files changed

+3710
-3658
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+3710
-3658
lines changed

src/doc/guide.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ $ editor main.rs
140140
```
141141

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

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

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

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

601601
## Expressions vs. Statements
602602

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

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

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

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

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

51845184
```{rust}
51855185
spawn(proc() {

src/doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ The two values of the boolean type are written `true` and `false`.
522522
### Symbols
523523

524524
```{.ebnf .gram}
525-
symbol : "::" "->"
525+
symbol : "::" | "->"
526526
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
527527
| ',' | ';' ;
528528
```

src/etc/gdb_rust_pretty_printing.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,27 @@ def rust_pretty_printer_lookup_function(val):
5454
return RustStructPrinter(val, false)
5555

5656
if enum_member_count == 1:
57-
if enum_members[0].name == None:
57+
first_variant_name = enum_members[0].name
58+
if first_variant_name == None:
5859
# This is a singleton enum
5960
return rust_pretty_printer_lookup_function(val[enum_members[0]])
6061
else:
61-
assert enum_members[0].name.startswith("RUST$ENCODED$ENUM$")
62+
assert first_variant_name.startswith("RUST$ENCODED$ENUM$")
6263
# This is a space-optimized enum
63-
last_separator_index = enum_members[0].name.rfind("$")
64+
last_separator_index = first_variant_name.rfind("$")
6465
second_last_separator_index = first_variant_name.rfind("$", 0, last_separator_index)
6566
disr_field_index = first_variant_name[second_last_separator_index + 1 :
6667
last_separator_index]
6768
disr_field_index = int(disr_field_index)
6869

6970
sole_variant_val = val[enum_members[0]]
7071
disr_field = get_field_at_index(sole_variant_val, disr_field_index)
71-
discriminant = int(sole_variant_val[disr_field])
72+
discriminant = sole_variant_val[disr_field]
73+
74+
# If the discriminant field is a fat pointer we have to consider the
75+
# first word as the true discriminant
76+
if discriminant.type.code == gdb.TYPE_CODE_STRUCT:
77+
discriminant = discriminant[get_field_at_index(discriminant, 0)]
7278

7379
if discriminant == 0:
7480
null_variant_name = first_variant_name[last_separator_index + 1:]
@@ -173,7 +179,7 @@ def to_string(self):
173179

174180
class IdentityPrinter:
175181
def __init__(self, string):
176-
self.string
182+
self.string = string
177183

178184
def to_string(self):
179185
return self.string

src/etc/licenseck.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
"rt/isaac/randport.cpp", # public domain
3939
"rt/isaac/rand.h", # public domain
4040
"rt/isaac/standard.h", # public domain
41-
"libstd/sync/mpsc_queue.rs", # BSD
42-
"libstd/sync/spsc_queue.rs", # BSD
43-
"libstd/sync/mpmc_bounded_queue.rs", # BSD
41+
"libstd/comm/mpsc_queue.rs", # BSD
42+
"libstd/comm/spsc_queue.rs", # BSD
4443
"test/bench/shootout-binarytrees.rs", # BSD
4544
"test/bench/shootout-chameneos-redux.rs", # BSD
4645
"test/bench/shootout-fannkuch-redux.rs", # BSD

src/etc/lldb_rust_formatters.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,14 @@ def print_enum_val(val, internal_dict):
138138
return "<invalid enum encoding: %s>" % first_variant_name
139139

140140
# Read the discriminant
141-
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
141+
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index)
142142

143-
if disr_val == 0:
143+
# If the discriminant field is a fat pointer we have to consider the
144+
# first word as the true discriminant
145+
if disr_val.GetType().GetTypeClass() == lldb.eTypeClassStruct:
146+
disr_val = disr_val.GetChildAtIndex(0)
147+
148+
if disr_val.GetValueAsUnsigned() == 0:
144149
# Null case: Print the name of the null-variant
145150
null_variant_name = first_variant_name[last_separator_index + 1:]
146151
return null_variant_name

src/liballoc/heap.rs

+55-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,59 @@ const MIN_ALIGN: uint = 8;
123123
target_arch = "x86_64"))]
124124
const MIN_ALIGN: uint = 16;
125125

126-
#[cfg(jemalloc)]
126+
#[cfg(external_funcs)]
127+
mod imp {
128+
extern {
129+
fn rust_allocate(size: uint, align: uint) -> *mut u8;
130+
fn rust_deallocate(ptr: *mut u8, old_size: uint, align: uint);
131+
fn rust_reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint) -> *mut u8;
132+
fn rust_reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
133+
align: uint) -> uint;
134+
fn rust_usable_size(size: uint, align: uint) -> uint;
135+
fn rust_stats_print();
136+
}
137+
138+
#[inline]
139+
pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 {
140+
rust_allocate(size, align)
141+
}
142+
143+
#[inline]
144+
pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
145+
align: uint) -> uint {
146+
rust_reallocate_inplace(ptr, old_size, size, align)
147+
}
148+
149+
#[inline]
150+
pub unsafe fn deallocate(ptr: *mut u8, old_size: uint, align: uint) {
151+
rust_deallocate(ptr, old_size, align)
152+
}
153+
154+
#[inline]
155+
pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
156+
align: uint) -> uint {
157+
rust_reallocate_inplace(ptr, old_size, size, align)
158+
}
159+
160+
#[inline]
161+
pub fn usable_size(size: uint, align: uint) -> uint {
162+
unsafe { rust_usable_size(size, align) }
163+
}
164+
165+
#[inline]
166+
pub fn stats_print() {
167+
unsafe { rust_stats_print() }
168+
}
169+
}
170+
171+
#[cfg(external_crate)]
172+
mod imp {
173+
extern crate external;
174+
pub use self::external::{allocate, deallocate, reallocate_inplace, reallocate};
175+
pub use self::external::{usable_size, stats_print};
176+
}
177+
178+
#[cfg(all(not(external_funcs), not(external_crate), jemalloc))]
127179
mod imp {
128180
use core::option::{None, Option};
129181
use core::ptr::{null_mut, null};
@@ -199,7 +251,7 @@ mod imp {
199251
}
200252
}
201253

202-
#[cfg(all(not(jemalloc), unix))]
254+
#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), unix))]
203255
mod imp {
204256
use core::cmp;
205257
use core::ptr;
@@ -260,7 +312,7 @@ mod imp {
260312
pub fn stats_print() {}
261313
}
262314

263-
#[cfg(all(not(jemalloc), windows))]
315+
#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), windows))]
264316
mod imp {
265317
use libc::{c_void, size_t};
266318
use libc;

src/libcollections/trie/set.rs

+125-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// FIXME(conventions): implement bounded iterators
12-
// FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub
1312
// FIXME(conventions): replace each_reverse by making iter DoubleEnded
1413
// FIXME(conventions): implement iter_mut and into_iter
1514

@@ -463,6 +462,90 @@ impl Extend<uint> for TrieSet {
463462
}
464463
}
465464

465+
#[unstable = "matches collection reform specification, waiting for dust to settle"]
466+
impl BitOr<TrieSet, TrieSet> for TrieSet {
467+
/// Returns the union of `self` and `rhs` as a new `TrieSet`.
468+
///
469+
/// # Example
470+
///
471+
/// ```
472+
/// use std::collections::TrieSet;
473+
///
474+
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
475+
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
476+
///
477+
/// let set: TrieSet = a | b;
478+
/// let v: Vec<uint> = set.iter().collect();
479+
/// assert_eq!(v, vec![1u, 2, 3, 4, 5]);
480+
/// ```
481+
fn bitor(&self, rhs: &TrieSet) -> TrieSet {
482+
self.union(rhs).collect()
483+
}
484+
}
485+
486+
#[unstable = "matches collection reform specification, waiting for dust to settle"]
487+
impl BitAnd<TrieSet, TrieSet> for TrieSet {
488+
/// Returns the intersection of `self` and `rhs` as a new `TrieSet`.
489+
///
490+
/// # Example
491+
///
492+
/// ```
493+
/// use std::collections::TrieSet;
494+
///
495+
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
496+
/// let b: TrieSet = vec![2, 3, 4].into_iter().collect();
497+
///
498+
/// let set: TrieSet = a & b;
499+
/// let v: Vec<uint> = set.iter().collect();
500+
/// assert_eq!(v, vec![2u, 3]);
501+
/// ```
502+
fn bitand(&self, rhs: &TrieSet) -> TrieSet {
503+
self.intersection(rhs).collect()
504+
}
505+
}
506+
507+
#[unstable = "matches collection reform specification, waiting for dust to settle"]
508+
impl BitXor<TrieSet, TrieSet> for TrieSet {
509+
/// Returns the symmetric difference of `self` and `rhs` as a new `TrieSet`.
510+
///
511+
/// # Example
512+
///
513+
/// ```
514+
/// use std::collections::TrieSet;
515+
///
516+
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
517+
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
518+
///
519+
/// let set: TrieSet = a ^ b;
520+
/// let v: Vec<uint> = set.iter().collect();
521+
/// assert_eq!(v, vec![1u, 2, 4, 5]);
522+
/// ```
523+
fn bitxor(&self, rhs: &TrieSet) -> TrieSet {
524+
self.symmetric_difference(rhs).collect()
525+
}
526+
}
527+
528+
#[unstable = "matches collection reform specification, waiting for dust to settle"]
529+
impl Sub<TrieSet, TrieSet> for TrieSet {
530+
/// Returns the difference of `self` and `rhs` as a new `TrieSet`.
531+
///
532+
/// # Example
533+
///
534+
/// ```
535+
/// use std::collections::TrieSet;
536+
///
537+
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
538+
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
539+
///
540+
/// let set: TrieSet = a - b;
541+
/// let v: Vec<uint> = set.iter().collect();
542+
/// assert_eq!(v, vec![1u, 2]);
543+
/// ```
544+
fn sub(&self, rhs: &TrieSet) -> TrieSet {
545+
self.difference(rhs).collect()
546+
}
547+
}
548+
466549
/// A forward iterator over a set.
467550
pub struct SetItems<'a> {
468551
iter: Entries<'a, ()>
@@ -569,6 +652,7 @@ impl<'a> Iterator<uint> for UnionItems<'a> {
569652
mod test {
570653
use std::prelude::*;
571654
use std::uint;
655+
use vec::Vec;
572656

573657
use super::TrieSet;
574658

@@ -738,4 +822,44 @@ mod test {
738822
&[1, 5, 9, 13, 19],
739823
&[1, 3, 5, 9, 11, 13, 16, 19, 24]);
740824
}
825+
826+
#[test]
827+
fn test_bit_or() {
828+
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
829+
let b: TrieSet = vec![3, 4, 5].into_iter().collect();
830+
831+
let set: TrieSet = a | b;
832+
let v: Vec<uint> = set.iter().collect();
833+
assert_eq!(v, vec![1u, 2, 3, 4, 5]);
834+
}
835+
836+
#[test]
837+
fn test_bit_and() {
838+
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
839+
let b: TrieSet = vec![2, 3, 4].into_iter().collect();
840+
841+
let set: TrieSet = a & b;
842+
let v: Vec<uint> = set.iter().collect();
843+
assert_eq!(v, vec![2u, 3]);
844+
}
845+
846+
#[test]
847+
fn test_bit_xor() {
848+
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
849+
let b: TrieSet = vec![3, 4, 5].into_iter().collect();
850+
851+
let set: TrieSet = a ^ b;
852+
let v: Vec<uint> = set.iter().collect();
853+
assert_eq!(v, vec![1u, 2, 4, 5]);
854+
}
855+
856+
#[test]
857+
fn test_sub() {
858+
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
859+
let b: TrieSet = vec![3, 4, 5].into_iter().collect();
860+
861+
let set: TrieSet = a - b;
862+
let v: Vec<uint> = set.iter().collect();
863+
assert_eq!(v, vec![1u, 2]);
864+
}
741865
}

0 commit comments

Comments
 (0)