Skip to content

Commit af1db28

Browse files
committed
---
yaml --- r: 79863 b: refs/heads/master c: b0e13e0 h: refs/heads/master i: 79861: 54ed520 79859: 32f1f51 79855: 2039d4e v: v3
1 parent 9faede5 commit af1db28

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 49eb7bd2716f59e0cd47c427a4c60f49e8ce6e50
2+
refs/heads/master: b0e13e0d0e61b4147c8c62856c50cf727f7c918f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 54ae2800ffb30513f89ce13d27ac3c8d095d98ac
55
refs/heads/try: 71bebebc37fbb229877da88dde13c2f35913bd77

trunk/doc/rust.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,12 +2459,25 @@ do k(3) |j| {
24592459
### For expressions
24602460

24612461
~~~~~~~~{.ebnf .gram}
2462-
for_expr : "for" pat "in" expr '{' block '}' ;
2462+
for_expr : "for" expr [ '|' ident_list '|' ] ? '{' block '}' ;
24632463
~~~~~~~~
24642464

2465-
A `for` expression is a syntactic construct for looping
2466-
over elements provided by an implementation of
2467-
`std::iterator::Iterator`.
2465+
A _for expression_ is similar to a [`do` expression](#do-expressions),
2466+
in that it provides a special block-form of lambda expression,
2467+
suited to passing the `block` function to a higher-order function implementing a loop.
2468+
2469+
In contrast to a `do` expression, a `for` expression is designed to work
2470+
with methods such as `each` and `times`, that require the body block to
2471+
return a boolean. The `for` expression accommodates this by implicitly
2472+
returning `true` at the end of each block, unless a `break` expression
2473+
is evaluated.
2474+
2475+
In addition, [`break`](#break-expressions) and [`loop`](#loop-expressions) expressions
2476+
are rewritten inside `for` expressions in the same way that `return` expressions are,
2477+
with a combination of local flag variables,
2478+
and early boolean-valued returns from the `block` function,
2479+
such that the meaning of `break` and `loop` is preserved in a primitive loop
2480+
when rewritten as a `for` loop controlled by a higher order function.
24682481

24692482
An example of a for loop over the contents of a vector:
24702483

trunk/src/libstd/hashmap.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,17 @@ impl<T:Hash + Eq> HashSet<T> {
687687
HashSet { map: HashMap::with_capacity(capacity) }
688688
}
689689

690+
/// Create an empty HashSet with space for at least `capacity`
691+
/// elements in the hash table, using `k0` and `k1` as the keys.
692+
///
693+
/// Warning: `k0` and `k1` are normally randomly generated, and
694+
/// are designed to allow HashSets to be resistant to attacks that
695+
/// cause many collisions and very poor performance. Setting them
696+
/// manually using this function can expose a DoS attack vector.
697+
pub fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashSet<T> {
698+
HashSet { map: HashMap::with_capacity_and_keys(k0, k1, capacity) }
699+
}
700+
690701
/// Reserve space for at least `n` elements in the hash table.
691702
pub fn reserve_at_least(&mut self, n: uint) {
692703
self.map.reserve_at_least(n)

0 commit comments

Comments
 (0)