Skip to content

Commit f38e452

Browse files
committed
---
yaml --- r: 105467 b: refs/heads/master c: 7437995 h: refs/heads/master i: 105465: 37ae7ff 105463: 438ee62 v: v3
1 parent 969491b commit f38e452

File tree

15 files changed

+77
-805
lines changed

15 files changed

+77
-805
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: 8063450e5733c99c0fc62898c9d5007e02bbdba5
2+
refs/heads/master: 7437995b3e68d3920e275ba5900b96a2ed254c66
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
55
refs/heads/try: db814977d07bd798feb24f6b74c00800ef458a13

trunk/src/libnum/bigint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl TotalOrd for BigUint {
117117
if s_len < o_len { return Less; }
118118
if s_len > o_len { return Greater; }
119119

120-
for (&self_i, &other_i) in self.data.iter().rev().zip(other.data.iter().rev()) {
120+
for (&self_i, &other_i) in self.data.rev_iter().zip(other.data.rev_iter()) {
121121
if self_i < other_i { return Less; }
122122
if self_i > other_i { return Greater; }
123123
}
@@ -788,7 +788,7 @@ impl BigUint {
788788

789789
let mut borrow = 0;
790790
let mut shifted_rev = Vec::with_capacity(self.data.len());
791-
for elem in self.data.iter().rev() {
791+
for elem in self.data.rev_iter() {
792792
shifted_rev.push((*elem >> n_bits) | borrow);
793793
borrow = *elem << (BigDigit::bits - n_bits);
794794
}

trunk/src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
288288
is_useful_specialized(cx, m, v, vec(n), n, left_ty)
289289
}
290290
ty::ty_unboxed_vec(..) | ty::ty_vec(..) => {
291-
let max_len = m.iter().rev().fold(0, |max_len, r| {
291+
let max_len = m.rev_iter().fold(0, |max_len, r| {
292292
match r.get(0).node {
293293
PatVec(ref before, _, ref after) => {
294294
cmp::max(before.len() + after.len(), max_len)

trunk/src/librustc/middle/liveness.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ impl<'a> Liveness<'a> {
879879
fn propagate_through_block(&mut self, blk: &Block, succ: LiveNode)
880880
-> LiveNode {
881881
let succ = self.propagate_through_opt_expr(blk.expr, succ);
882-
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
882+
blk.stmts.rev_iter().fold(succ, |succ, stmt| {
883883
self.propagate_through_stmt(*stmt, succ)
884884
})
885885
}
@@ -980,7 +980,7 @@ impl<'a> Liveness<'a> {
980980
this.ir.tcx.sess.span_bug(expr.span, "no registered caps");
981981
}
982982
};
983-
caps.deref().iter().rev().fold(succ, |succ, cap| {
983+
caps.deref().rev_iter().fold(succ, |succ, cap| {
984984
this.init_from_succ(cap.ln, succ);
985985
let var = this.variable(cap.var_nid, expr.span);
986986
this.acc(cap.ln, var, ACC_READ | ACC_USE);
@@ -1121,7 +1121,7 @@ impl<'a> Liveness<'a> {
11211121

11221122
ExprStruct(_, ref fields, with_expr) => {
11231123
let succ = self.propagate_through_opt_expr(with_expr, succ);
1124-
fields.iter().rev().fold(succ, |succ, field| {
1124+
fields.rev_iter().fold(succ, |succ, field| {
11251125
self.propagate_through_expr(field.expr, succ)
11261126
})
11271127
}
@@ -1173,14 +1173,14 @@ impl<'a> Liveness<'a> {
11731173
}
11741174

11751175
ExprInlineAsm(ref ia) => {
1176-
let succ = ia.outputs.iter().rev().fold(succ, |succ, &(_, expr)| {
1176+
let succ = ia.outputs.rev_iter().fold(succ, |succ, &(_, expr)| {
11771177
// see comment on lvalues in
11781178
// propagate_through_lvalue_components()
11791179
let succ = self.write_lvalue(expr, succ, ACC_WRITE);
11801180
self.propagate_through_lvalue_components(expr, succ)
11811181
});
11821182
// Inputs are executed first. Propagate last because of rev order
1183-
ia.inputs.iter().rev().fold(succ, |succ, &(_, expr)| {
1183+
ia.inputs.rev_iter().fold(succ, |succ, &(_, expr)| {
11841184
self.propagate_through_expr(expr, succ)
11851185
})
11861186
}

trunk/src/librustc/middle/resolve.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5520,8 +5520,7 @@ impl<'a> Resolver<'a> {
55205520
if idents.len() == 0 {
55215521
return ~"???";
55225522
}
5523-
return self.idents_to_str(idents.move_iter()
5524-
.rev()
5523+
return self.idents_to_str(idents.move_rev_iter()
55255524
.collect::<Vec<ast::Ident>>()
55265525
.as_slice());
55275526
}

trunk/src/librustc/middle/trans/cabi_x86.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ pub fn compute_abi_info(ccx: &CrateContext,
6363
ret_ty = ArgType::direct(rty, None, None, None);
6464
}
6565

66-
for &a in atys.iter() {
67-
arg_tys.push(ArgType::direct(a, None, None, None));
66+
for &t in atys.iter() {
67+
let ty = match t.kind() {
68+
Struct => {
69+
ArgType::indirect(t, Some(ByValAttribute))
70+
}
71+
_ => ArgType::direct(t, None, None, None),
72+
};
73+
arg_tys.push(ty);
6874
}
6975

7076
return FnType {

trunk/src/librustc/middle/typeck/check/vtable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ fn lookup_vtables(vcx: &VtableContext,
9494
// We do this backwards for reasons discussed above.
9595
assert_eq!(substs.tps.len(), type_param_defs.len());
9696
let mut result: Vec<vtable_param_res> =
97-
substs.tps.iter()
98-
.rev()
97+
substs.tps.rev_iter()
9998
.zip(type_param_defs.rev_iter())
10099
.map(|(ty, def)|
101100
lookup_vtables_for_param(vcx, span, Some(substs),

trunk/src/libstd/option.rs

Lines changed: 20 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,21 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Optional values
11+
//! Optionally nullable values (`Option` type)
1212
//!
13-
//! Type `Option` represents an optional value: every `Option`
14-
//! is either `Some` and contains a value, or `None`, and
15-
//! does not. `Option` types are very common in Rust code, as
16-
//! they have a number of uses:
13+
//! Type `Option` represents an optional value.
1714
//!
18-
//! * Initial values
19-
//! * Return values for functions that are not defined
20-
//! over their entire input range (partial functions)
21-
//! * Return value for otherwise reporting simple errors, where `None` is
22-
//! returned on error
23-
//! * Optional struct fields
24-
//! * Struct fields that can be loaned or "taken"
25-
//! * Optional function arguments
26-
//! * Nullable pointers
27-
//! * Swapping things out of difficult situations
15+
//! Every `Option<T>` value can either be `Some(T)` or `None`. Where in other
16+
//! languages you might use a nullable type, in Rust you would use an option
17+
//! type.
2818
//!
29-
//! Options are commonly paired with pattern matching to query the presence
19+
//! Options are most commonly used with pattern matching to query the presence
3020
//! of a value and take action, always accounting for the `None` case.
3121
//!
32-
//! ```
33-
//! # // FIXME This is not the greatest first example
34-
//! // cow_says contains the word "moo"
35-
//! let cow_says = Some("moo");
36-
//! // dog_says does not contain a value
37-
//! let dog_says: Option<&str> = None;
38-
//!
39-
//! // Pattern match to retrieve the value
40-
//! match (cow_says, dog_says) {
41-
//! (Some(cow_words), Some(dog_words)) => {
42-
//! println!("Cow says {} and dog says {}!", cow_words, dog_words);
43-
//! }
44-
//! (Some(cow_words), None) => println!("Cow says {}", cow_words),
45-
//! (None, Some(dog_words)) => println!("Dog says {}", dog_words),
46-
//! (None, None) => println!("Cow and dog are suspiciously silent")
47-
//! }
48-
//! ```
49-
//!
50-
//
51-
// FIXME: Show how `Option` is used in practice, with lots of methods
52-
//
53-
//! # Options and pointers ("nullable" pointers)
54-
//!
55-
//! Rust's pointer types must always point to a valid location; there are
56-
//! no "null" pointers. Instead, Rust has *optional* pointers, like
57-
//! the optional owned box, `Option<~T>`.
58-
//!
59-
//! The following example uses `Option` to create an optional box of
60-
//! `int`. Notice that in order to use the inner `int` value first the
61-
//! `check_optional` function needs to use pattern matching to
62-
//! determine whether the box has a value (i.e. it is `Some(...)`) or
63-
//! not (`None`).
64-
//!
65-
//! ```
66-
//! let optional: Option<~int> = None;
67-
//! check_optional(&optional);
22+
//! # Example
6823
//!
69-
//! let optional: Option<~int> = Some(~9000);
70-
//! check_optional(&optional);
71-
//!
72-
//! fn check_optional(optional: &Option<~int>) {
73-
//! match *optional {
74-
//! Some(ref p) => println!("have value {}", p),
75-
//! None => println!("have no value")
76-
//! }
77-
//! }
7824
//! ```
79-
//!
80-
//! This usage of `Option` to create safe nullable pointers is so
81-
//! common that Rust does special optimizations to make the
82-
//! representation of `Option<~T>` a single pointer. Optional pointers
83-
//! in Rust are stored as efficiently as any other pointer type.
84-
//!
85-
//! # Examples
86-
//!
87-
//! Basic pattern matching on `Option`:
88-
//!
89-
//! ```
90-
//! let msg = Some("howdy");
25+
//! let msg = Some(~"howdy");
9126
//!
9227
//! // Take a reference to the contained string
9328
//! match msg {
@@ -98,45 +33,9 @@
9833
//! // Remove the contained string, destroying the Option
9934
//! let unwrapped_msg = match msg {
10035
//! Some(m) => m,
101-
//! None => "default message"
36+
//! None => ~"default message"
10237
//! };
10338
//! ```
104-
//!
105-
//! Initialize a result to `None` before a loop:
106-
//!
107-
//! ```
108-
//! enum Kingdom { Plant(uint, &'static str), Animal(uint, &'static str) }
109-
//!
110-
//! // A list of data to search through.
111-
//! let all_the_big_things = [
112-
//! Plant(250, "redwood"),
113-
//! Plant(230, "noble fir"),
114-
//! Plant(229, "sugar pine"),
115-
//! Animal(25, "blue whale"),
116-
//! Animal(19, "fin whale"),
117-
//! Animal(15, "north pacific right whale"),
118-
//! ];
119-
//!
120-
//! // We're going to search for the name of the biggest animal,
121-
//! // but to start with we've just got `None`.
122-
//! let mut name_of_biggest_animal = None;
123-
//! let mut size_of_biggest_animal = 0;
124-
//! for big_thing in all_the_big_things.iter() {
125-
//! match *big_thing {
126-
//! Animal(size, name) if size > size_of_biggest_animal => {
127-
//! // Now we've found the name of some big animal
128-
//! size_of_biggest_animal = size;
129-
//! name_of_biggest_animal = Some(name);
130-
//! }
131-
//! Animal(..) | Plant(..) => ()
132-
//! }
133-
//! }
134-
//!
135-
//! match name_of_biggest_animal {
136-
//! Some(name) => println!("the biggest animal is {}", name),
137-
//! None => println!("there are no animals :(")
138-
//! }
139-
//! ```
14039
14140
use any::Any;
14241
use clone::Clone;
@@ -147,7 +46,7 @@ use kinds::Send;
14746
use mem;
14847
use vec;
14948

150-
/// The `Option`
49+
/// The option type
15150
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show)]
15251
pub enum Option<T> {
15352
/// No value
@@ -165,7 +64,7 @@ impl<T> Option<T> {
16564
// Querying the contained values
16665
/////////////////////////////////////////////////////////////////////////
16766

168-
/// Returns `true` if the option is a `Some` value
67+
/// Returns true if the option contains a `Some` value
16968
#[inline]
17069
pub fn is_some(&self) -> bool {
17170
match *self {
@@ -174,7 +73,7 @@ impl<T> Option<T> {
17473
}
17574
}
17675

177-
/// Returns `true` if the option is a `None` value
76+
/// Returns true if the option equals `None`
17877
#[inline]
17978
pub fn is_none(&self) -> bool {
18079
!self.is_some()
@@ -185,21 +84,6 @@ impl<T> Option<T> {
18584
/////////////////////////////////////////////////////////////////////////
18685

18786
/// Convert from `Option<T>` to `Option<&T>`
188-
///
189-
/// # Example
190-
///
191-
/// Convert an `Option<~str>` into an `Option<int>`, preserving the original.
192-
/// The `map` method takes the `self` argument by value, consuming the original,
193-
/// so this technique uses `as_ref` to first take an `Option` to a reference
194-
/// to the value inside the original.
195-
///
196-
/// ```
197-
/// let num_as_str: Option<~str> = Some(~"10");
198-
/// // First, cast `Option<~str>` to `Option<&~str>` with `as_ref`,
199-
/// // then consume *that* with `map`, leaving `num_as_str` on the stack.
200-
/// let num_as_int: Option<uint> = num_as_str.as_ref().map(|n| n.len());
201-
/// println!("still can print num_as_str: {}", num_as_str);
202-
/// ```
20387
#[inline]
20488
pub fn as_ref<'r>(&'r self) -> Option<&'r T> {
20589
match *self { Some(ref x) => Some(x), None => None }
@@ -234,9 +118,6 @@ impl<T> Option<T> {
234118
/////////////////////////////////////////////////////////////////////////
235119

236120
/// Unwraps an option, yielding the content of a `Some`
237-
///
238-
/// # Failure
239-
///
240121
/// Fails if the value is a `None` with a custom failure message provided by `msg`.
241122
#[inline]
242123
pub fn expect<M: Any + Send>(self, msg: M) -> T {
@@ -246,11 +127,14 @@ impl<T> Option<T> {
246127
}
247128
}
248129

249-
/// Moves a value out of an option type and returns it, consuming the `Option`.
130+
/// Moves a value out of an option type and returns it.
131+
///
132+
/// Useful primarily for getting strings, vectors and unique pointers out
133+
/// of option types without copying them.
250134
///
251135
/// # Failure
252136
///
253-
/// Fails if the self value equals `None`.
137+
/// Fails if the value equals `None`.
254138
///
255139
/// # Safety note
256140
///
@@ -287,17 +171,7 @@ impl<T> Option<T> {
287171
// Transforming contained values
288172
/////////////////////////////////////////////////////////////////////////
289173

290-
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value
291-
///
292-
/// # Example
293-
///
294-
/// Convert an `Option<~str>` into an `Option<uint>`, consuming the original:
295-
///
296-
/// ```
297-
/// let num_as_str: Option<~str> = Some(~"10");
298-
/// // `Option::map` takes self *by value*, consuming `num_as_str`
299-
/// let num_as_int: Option<uint> = num_as_str.map(|n| n.len());
300-
/// ```
174+
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
301175
#[inline]
302176
pub fn map<U>(self, f: |T| -> U) -> Option<U> {
303177
match self { Some(x) => Some(f(x)), None => None }
@@ -485,28 +359,7 @@ impl<T> Option<T> {
485359
}
486360

487361
impl<T: Default> Option<T> {
488-
/// Returns the contained value or a default
489-
///
490-
/// Consumes the `self` argument then, if `Some`, returns the contained
491-
/// value, otherwise if `None`, returns the default value for that
492-
/// type.
493-
///
494-
/// # Example
495-
///
496-
/// Convert a string to an integer, turning poorly-formed strings
497-
/// into 0 (the default value for integers). `from_str` converts
498-
/// a string to any other type that implements `FromStr`, returning
499-
/// `None` on error.
500-
///
501-
/// ```
502-
/// let good_year_from_input = "1909";
503-
/// let bad_year_from_input = "190blarg";
504-
/// let good_year = from_str(good_year_from_input).unwrap_or_default();
505-
/// let bad_year = from_str(bad_year_from_input).unwrap_or_default();
506-
///
507-
/// assert_eq!(1909, good_year);
508-
/// assert_eq!(0, bad_year);
509-
/// ```
362+
/// Returns the contained value or default (for this type)
510363
#[inline]
511364
pub fn unwrap_or_default(self) -> T {
512365
match self {
@@ -529,10 +382,7 @@ impl<T> Default for Option<T> {
529382
// The Option Iterator
530383
/////////////////////////////////////////////////////////////////////////////
531384

532-
/// An `Option` iterator that yields either one or zero elements
533-
///
534-
/// The `Item` iterator is returned by the `iter`, `mut_iter` and `move_iter`
535-
/// methods on `Option`.
385+
/// An iterator that yields either one or zero elements
536386
#[deriving(Clone)]
537387
pub struct Item<A> {
538388
priv opt: Option<A>

0 commit comments

Comments
 (0)