Skip to content

Commit 7ea39cd

Browse files
committed
---
yaml --- r: 115435 b: refs/heads/try c: b0977b1 h: refs/heads/master i: 115433: c364645 115431: f8c8a9b v: v3
1 parent a30fc01 commit 7ea39cd

File tree

181 files changed

+1797
-1117
lines changed

Some content is hidden

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

181 files changed

+1797
-1117
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
5-
refs/heads/try: 825f6ace1d8692af23f4a2842c87cb2dcc864fad
5+
refs/heads/try: b0977b1e0f7ba53b6301e2d5f7b26dd2d9c72fbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/LICENSE-MIT

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Copyright (c) 2006-2009 Graydon Hoare
2-
Copyright (c) 2009-2014 Mozilla Foundation
1+
Copyright (c) 2014 The Rust Project Developers
32

43
Permission is hereby granted, free of charge, to any
54
person obtaining a copy of this software and associated

branches/try/src/doc/guide-pointers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ enum List<T> {
186186
Nil,
187187
Cons(T, ~List<T>),
188188
}
189-
189+
190190
fn main() {
191191
let list: List<int> = Cons(1, ~Cons(2, ~Cons(3, ~Nil)));
192192
println!("{:?}", list);
@@ -251,7 +251,7 @@ struct.
251251

252252
> **Note**: the `@` form of managed pointers is deprecated and behind a
253253
> feature gate (it requires a `#![feature(managed_pointers)]` attribute on
254-
> the crate root; remember the semicolon!). There are replacements, currently
254+
> the crate root). There are replacements, currently
255255
> there is `std::rc::Rc` and `std::gc::Gc` for shared ownership via reference
256256
> counting and garbage collection respectively.
257257
@@ -266,7 +266,7 @@ struct Point {
266266
x: int,
267267
y: int,
268268
}
269-
269+
270270
fn main() {
271271
let a = ~Point { x: 10, y: 20 };
272272
let b = a;
@@ -297,7 +297,7 @@ struct Point {
297297
x: int,
298298
y: int,
299299
}
300-
300+
301301
fn main() {
302302
let a = @Point { x: 10, y: 20 };
303303
let b = a;
@@ -361,7 +361,7 @@ So how is this hard? Well, because we're ignoring ownership, the compiler needs
361361
to take great care to make sure that everything is safe. Despite their complete
362362
safety, a reference's representation at runtime is the same as that of
363363
an ordinary pointer in a C program. They introduce zero overhead. The compiler
364-
does all safety checks at compile time.
364+
does all safety checks at compile time.
365365

366366
This theory is called 'region pointers,' and involve a concept called
367367
'lifetimes'. Here's the simple explanation: would you expect this code to
@@ -477,7 +477,7 @@ fn main() {
477477
You may think that this gives us terrible performance: return a value and then
478478
immediately box it up?!?! Isn't that the worst of both worlds? Rust is smarter
479479
than that. There is no copy in this code. `main` allocates enough room for the
480-
`@int`, passes a pointer to that memory into `foo` as `x`, and then `foo` writes
480+
`@int`, passes a pointer to that memory into `foo` as `x`, and then `foo` writes
481481
the value straight into that pointer. This writes the return value directly into
482482
the allocated box.
483483

branches/try/src/doc/guide-tasks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ fn print_message() { println!("I am running in a different task!"); }
101101
spawn(print_message);
102102
103103
// Print something more profound in a different task using a lambda expression
104+
// This uses the proc() keyword to assign to spawn a function with no name
105+
// That function will call println!(...) as requested
104106
spawn(proc() println!("I am also running in a different task!") );
105107
~~~~
106108

branches/try/src/doc/tutorial.md

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,38 +1720,103 @@ environment (sometimes referred to as "capturing" variables in their
17201720
environment). For example, you couldn't write the following:
17211721
17221722
~~~~ {.ignore}
1723-
let foo = 10;
1723+
let x = 3;
17241724
1725-
fn bar() -> int {
1726-
return foo; // `bar` cannot refer to `foo`
1727-
}
1725+
// `fun` cannot refer to `x`
1726+
fn fun() -> () { println!("{}", x); }
17281727
~~~~
17291728
1730-
Rust also supports _closures_, functions that can access variables in
1731-
the enclosing scope.
1729+
A _closure_ does support accessing the enclosing scope; below we will create
1730+
2 _closures_ (nameless functions). Compare how `||` replaces `()` and how
1731+
they try to access `x`:
17321732
1733-
~~~~
1734-
fn call_closure_with_ten(b: |int|) { b(10); }
1733+
~~~~ {.ignore}
1734+
let x = 3;
17351735
1736-
let captured_var = 20;
1737-
let closure = |arg| println!("captured_var={}, arg={}", captured_var, arg);
1736+
// `fun` is an invalid definition
1737+
fn fun () -> () { println!("{}", x) } // cannot capture from enclosing scope
1738+
let closure = || -> () { println!("{}", x) }; // can capture from enclosing scope
17381739
1739-
call_closure_with_ten(closure);
1740+
// `fun_arg` is an invalid definition
1741+
fn fun_arg (arg: int) -> () { println!("{}", arg + x) } // cannot capture
1742+
let closure_arg = |arg: int| -> () { println!("{}", arg + x) }; // can capture
1743+
// ^
1744+
// Requires a type because the implementation needs to know which `+` to use.
1745+
// In the future, the implementation may not need the help.
1746+
1747+
fun(); // Still won't work
1748+
closure(); // Prints: 3
1749+
1750+
fun_arg(7); // Still won't work
1751+
closure_arg(7); // Prints: 10
17401752
~~~~
17411753
17421754
Closures begin with the argument list between vertical bars and are followed by
17431755
a single expression. Remember that a block, `{ <expr1>; <expr2>; ... }`, is
17441756
considered a single expression: it evaluates to the result of the last
17451757
expression it contains if that expression is not followed by a semicolon,
1746-
otherwise the block evaluates to `()`.
1758+
otherwise the block evaluates to `()`, the unit value.
1759+
1760+
In general, return types and all argument types must be specified
1761+
explicitly for function definitions. (As previously mentioned in the
1762+
[Functions section](#functions), omitting the return type from a
1763+
function declaration is synonymous with an explicit declaration of
1764+
return type unit, `()`.)
1765+
1766+
~~~~ {.ignore}
1767+
fn fun (x: int) { println!("{}", x) } // this is same as saying `-> ()`
1768+
fn square(x: int) -> uint { (x * x) as uint } // other return types are explicit
1769+
1770+
// Error: mismatched types: expected `()` but found `uint`
1771+
fn badfun(x: int) { (x * x) as uint }
1772+
~~~~
1773+
1774+
On the other hand, the compiler can usually infer both the argument
1775+
and return types for a closure expression; therefore they are often
1776+
omitted, since both a human reader and the compiler can deduce the
1777+
types from the immediate context. This is in contrast to function
1778+
declarations, which require types to be specified and are not subject
1779+
to type inference. Compare:
17471780
1748-
The types of the arguments are generally omitted, as is the return type,
1749-
because the compiler can almost always infer them. In the rare case where the
1750-
compiler needs assistance, though, the arguments and return types may be
1751-
annotated.
1781+
~~~~ {.ignore}
1782+
// `fun` as a function declaration cannot infer the type of `x`, so it must be provided
1783+
fn fun (x: int) { println!("{}", x) }
1784+
let closure = |x | { println!("{}", x) }; // infers `x: int`, return type `()`
1785+
1786+
// For closures, omitting a return type is *not* synonymous with `-> ()`
1787+
let add_3 = |y | { 3i + y }; // infers `y: int`, return type `int`.
1788+
1789+
fun(10); // Prints 10
1790+
closure(20); // Prints 20
1791+
closure(add_3(30)); // Prints 33
17521792
1793+
fun("String"); // Error: mismatched types
1794+
1795+
// Error: mismatched types
1796+
// inference already assigned `closure` the type `|int| -> ()`
1797+
closure("String");
17531798
~~~~
1754-
let square = |x: int| -> uint { (x * x) as uint };
1799+
1800+
In cases where the compiler needs assistance, the arguments and return
1801+
types may be annotated on closures, using the same notation as shown
1802+
earlier. In the example below, since different types provide an
1803+
implementation for the operator `*`, the argument type for the `x`
1804+
parameter must be explicitly provided.
1805+
1806+
~~~~{.ignore}
1807+
// Error: the type of `x` must be known to be used with `x * x`
1808+
let square = |x | -> uint { (x * x) as uint };
1809+
~~~~
1810+
1811+
In the corrected version, the argument type is explicitly annotated,
1812+
while the return type can still be inferred.
1813+
1814+
~~~~
1815+
let square_explicit = |x: int| -> uint { (x * x) as uint };
1816+
let square_infer = |x: int| { (x * x) as uint };
1817+
1818+
println!("{}", square_explicit(20)); // 400
1819+
println!("{}", square_infer(-20)); // 400
17551820
~~~~
17561821
17571822
There are several forms of closure, each with its own role. The most

branches/try/src/etc/emacs/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ To install manually, check out this repository and add this to your
1212

1313
```lisp
1414
(add-to-list 'load-path "/path/to/rust-mode/")
15-
(require 'rust-mode)
15+
(autoload 'rust-mode "rust-mode" nil t)
16+
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
1617
```
1718

18-
`rust-mode` will automatically be associated with `.rs` files. To enable it
19-
explicitly, do <kbd>M-x rust-mode</kbd>.
19+
This associates `rust-mode` with `.rs` files. To enable it explicitly, do
20+
<kbd>M-x rust-mode</kbd>.
2021

2122
### `package.el` installation via Marmalade or MELPA
2223

branches/try/src/etc/emacs/rust-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
;; Font-locking definitions and helpers
170170
(defconst rust-mode-keywords
171171
'("as"
172-
"break"
172+
"box" "break"
173173
"continue" "crate"
174174
"do"
175175
"else" "enum" "extern"

branches/try/src/libarena/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ mod tests {
517517
#[bench]
518518
pub fn bench_copy_nonarena(b: &mut Bencher) {
519519
b.iter(|| {
520-
~Point {
520+
box Point {
521521
x: 1,
522522
y: 2,
523523
z: 3,
@@ -569,7 +569,7 @@ mod tests {
569569
#[bench]
570570
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
571571
b.iter(|| {
572-
~Noncopy {
572+
box Noncopy {
573573
string: "hello world".to_owned(),
574574
array: vec!( 1, 2, 3, 4, 5 ),
575575
}

branches/try/src/libcollections/btree.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ impl<K: Clone + TotalOrd, V: Clone> Leaf<K, V> {
377377
== Less);
378378
let branch_return = Node::new_branch(vec!(BranchElt::new(midpoint.key.clone(),
379379
midpoint.value.clone(),
380-
~Node::new_leaf(left_leaf))),
381-
~Node::new_leaf(right_leaf));
380+
box Node::new_leaf(left_leaf))),
381+
box Node::new_leaf(right_leaf));
382382
return (branch_return, true);
383383
}
384384
(Node::new_leaf(self.elts.clone()), true)
@@ -540,10 +540,10 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
540540
//so we can return false.
541541
LeafNode(..) => {
542542
if index.unwrap() == self.elts.len() {
543-
self.rightmost_child = ~new_branch.clone();
543+
self.rightmost_child = box new_branch.clone();
544544
}
545545
else {
546-
self.elts.get_mut(index.unwrap()).left = ~new_branch.clone();
546+
self.elts.get_mut(index.unwrap()).left = box new_branch.clone();
547547
}
548548
return (Node::new_branch(self.clone().elts,
549549
self.clone().rightmost_child),
@@ -561,10 +561,10 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
561561
//and return it, saying we have inserted a new element.
562562
LeafNode(..) => {
563563
if index.unwrap() == self.elts.len() {
564-
self.rightmost_child = ~new_branch;
564+
self.rightmost_child = box new_branch;
565565
}
566566
else {
567-
self.elts.get_mut(index.unwrap()).left = ~new_branch;
567+
self.elts.get_mut(index.unwrap()).left = box new_branch;
568568
}
569569
return (Node::new_branch(self.clone().elts,
570570
self.clone().rightmost_child),
@@ -604,9 +604,9 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
604604
new_branch = Node::new_branch(
605605
vec!(BranchElt::new(midpoint.clone().key,
606606
midpoint.clone().value,
607-
~Node::new_branch(new_left,
607+
box Node::new_branch(new_left,
608608
midpoint.clone().left))),
609-
~Node::new_branch(new_right, self.clone().rightmost_child));
609+
box Node::new_branch(new_right, self.clone().rightmost_child));
610610
return (new_branch, true);
611611
}
612612
}

branches/try/src/libcollections/dlist.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<T> Deque<T> for DList<T> {
238238
///
239239
/// O(1)
240240
fn push_front(&mut self, elt: T) {
241-
self.push_front_node(~Node::new(elt))
241+
self.push_front_node(box Node::new(elt))
242242
}
243243

244244
/// Remove the first element and return it, or None if the list is empty
@@ -252,7 +252,7 @@ impl<T> Deque<T> for DList<T> {
252252
///
253253
/// O(1)
254254
fn push_back(&mut self, elt: T) {
255-
self.push_back_node(~Node::new(elt))
255+
self.push_back_node(box Node::new(elt))
256256
}
257257

258258
/// Remove the last element and return it, or None if the list is empty
@@ -555,7 +555,7 @@ impl<'a, A> MutItems<'a, A> {
555555
impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
556556
#[inline]
557557
fn insert_next(&mut self, elt: A) {
558-
self.insert_next_node(~Node::new(elt))
558+
self.insert_next_node(box Node::new(elt))
559559
}
560560

561561
#[inline]
@@ -675,19 +675,19 @@ mod tests {
675675
assert_eq!(m.pop_front(), None);
676676
assert_eq!(m.pop_back(), None);
677677
assert_eq!(m.pop_front(), None);
678-
m.push_front(~1);
678+
m.push_front(box 1);
679679
assert_eq!(m.pop_front(), Some(~1));
680-
m.push_back(~2);
681-
m.push_back(~3);
680+
m.push_back(box 2);
681+
m.push_back(box 3);
682682
assert_eq!(m.len(), 2);
683683
assert_eq!(m.pop_front(), Some(~2));
684684
assert_eq!(m.pop_front(), Some(~3));
685685
assert_eq!(m.len(), 0);
686686
assert_eq!(m.pop_front(), None);
687-
m.push_back(~1);
688-
m.push_back(~3);
689-
m.push_back(~5);
690-
m.push_back(~7);
687+
m.push_back(box 1);
688+
m.push_back(box 3);
689+
m.push_back(box 5);
690+
m.push_back(box 7);
691691
assert_eq!(m.pop_front(), Some(~1));
692692

693693
let mut n = DList::new();

branches/try/src/libcollections/lru_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
9393
let cache = LruCache {
9494
map: HashMap::new(),
9595
max_size: capacity,
96-
head: unsafe{ cast::transmute(~mem::uninit::<LruEntry<K, V>>()) },
96+
head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
9797
};
9898
unsafe {
9999
(*cache.head).next = cache.head;
@@ -111,7 +111,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
111111
(node_ptr, None)
112112
}
113113
None => {
114-
let mut node = ~LruEntry::new(k, v);
114+
let mut node = box LruEntry::new(k, v);
115115
let node_ptr: *mut LruEntry<K, V> = &mut *node;
116116
(node_ptr, Some(node))
117117
}

branches/try/src/libcollections/priority_queue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,19 @@ mod tests {
273273
let mut heap = PriorityQueue::from_vec(vec!(~2, ~4, ~9));
274274
assert_eq!(heap.len(), 3);
275275
assert!(*heap.top() == ~9);
276-
heap.push(~11);
276+
heap.push(box 11);
277277
assert_eq!(heap.len(), 4);
278278
assert!(*heap.top() == ~11);
279-
heap.push(~5);
279+
heap.push(box 5);
280280
assert_eq!(heap.len(), 5);
281281
assert!(*heap.top() == ~11);
282-
heap.push(~27);
282+
heap.push(box 27);
283283
assert_eq!(heap.len(), 6);
284284
assert!(*heap.top() == ~27);
285-
heap.push(~3);
285+
heap.push(box 3);
286286
assert_eq!(heap.len(), 7);
287287
assert!(*heap.top() == ~27);
288-
heap.push(~103);
288+
heap.push(box 103);
289289
assert_eq!(heap.len(), 8);
290290
assert!(*heap.top() == ~103);
291291
}

0 commit comments

Comments
 (0)