Skip to content

Commit de82bde

Browse files
committed
auto merge of #6944 : pcwalton/rust/multiple-patterns-in-let, r=nikomatsakis
r? @nikomatsakis
2 parents 9873f67 + 8114d0e commit de82bde

Some content is hidden

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

83 files changed

+450
-290
lines changed

doc/rust.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,9 @@ An example of a for loop over the contents of a vector:
23252325
~~~~
23262326
# type foo = int;
23272327
# fn bar(f: foo) { }
2328-
# let a = 0, b = 0, c = 0;
2328+
# let a = 0;
2329+
# let b = 0;
2330+
# let c = 0;
23292331
23302332
let v: &[foo] = &[a, b, c];
23312333
@@ -3000,7 +3002,7 @@ allocated within the stack's memory. The value is a part of the stack frame.
30003002

30013003
Local variables are immutable unless declared with `let mut`. The
30023004
`mut` keyword applies to all local variables declared within that
3003-
declaration (so `let mut x, y` declares two mutable variables, `x` and
3005+
declaration (so `let mut (x, y) = ...` declares two mutable variables, `x` and
30043006
`y`).
30053007

30063008
Function parameters are immutable unless declared with `mut`. The

doc/tutorial-ffi.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub struct Unique<T> {
159159
priv ptr: *mut T
160160
}
161161
162-
pub impl<T: Owned> Unique<T> {
163-
fn new(value: T) -> Unique<T> {
162+
impl<T: Owned> Unique<T> {
163+
pub fn new(value: T) -> Unique<T> {
164164
unsafe {
165165
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
166166
assert!(!ptr::is_null(ptr));
@@ -171,12 +171,12 @@ pub impl<T: Owned> Unique<T> {
171171
}
172172
173173
// the 'r lifetime results in the same semantics as `&*x` with ~T
174-
fn borrow<'r>(&'r self) -> &'r T {
174+
pub fn borrow<'r>(&'r self) -> &'r T {
175175
unsafe { cast::copy_lifetime(self, &*self.ptr) }
176176
}
177177
178178
// the 'r lifetime results in the same semantics as `&mut *x` with ~T
179-
fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
179+
pub fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
180180
unsafe { cast::copy_mut_lifetime(self, &mut *self.ptr) }
181181
}
182182
}

doc/tutorial-macros.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ doing nothing otherwise:
1313
~~~~
1414
# enum t { special_a(uint), special_b(uint) };
1515
# fn f() -> uint {
16-
# let input_1 = special_a(0), input_2 = special_a(0);
16+
# let input_1 = special_a(0);
17+
# let input_2 = special_a(0);
1718
match input_1 {
1819
special_a(x) => { return x; }
1920
_ => {}
@@ -38,7 +39,8 @@ the pattern in the above code:
3839
~~~~
3940
# enum t { special_a(uint), special_b(uint) };
4041
# fn f() -> uint {
41-
# let input_1 = special_a(0), input_2 = special_a(0);
42+
# let input_1 = special_a(0);
43+
# let input_2 = special_a(0);
4244
macro_rules! early_return(
4345
($inp:expr $sp:ident) => ( // invoke it like `(input_5 special_e)`
4446
match $inp {
@@ -155,7 +157,8 @@ instead of `*` to mean "at least one".
155157
~~~~
156158
# enum t { special_a(uint),special_b(uint),special_c(uint),special_d(uint)};
157159
# fn f() -> uint {
158-
# let input_1 = special_a(0), input_2 = special_a(0);
160+
# let input_1 = special_a(0);
161+
# let input_2 = special_a(0);
159162
macro_rules! early_return(
160163
($inp:expr, [ $($sp:ident)|+ ]) => (
161164
match $inp {

src/libextra/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
134134
while idx < fill {
135135
let tydesc_data: *uint = transmute(ptr::offset(buf, idx));
136136
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
137-
let size = (*tydesc).size, align = (*tydesc).align;
137+
let (size, align) = ((*tydesc).size, (*tydesc).align);
138138

139139
let after_tydesc = idx + sys::size_of::<*TypeDesc>();
140140

src/libextra/fileinput.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ impl FileInput {
194194
arguments. `"-"` represents `stdin`.
195195
*/
196196
pub fn from_args() -> FileInput {
197-
let args = os::args(),
198-
pathed = pathify(args.tail(), true);
197+
let args = os::args();
198+
let pathed = pathify(args.tail(), true);
199199
FileInput::from_vec(pathed)
200200
}
201201

@@ -222,11 +222,11 @@ impl FileInput {
222222
return false;
223223
}
224224

225-
let path_option = self.fi.files.shift(),
226-
file = match path_option {
227-
None => io::stdin(),
228-
Some(ref path) => io::file_reader(path).get()
229-
};
225+
let path_option = self.fi.files.shift();
226+
let file = match path_option {
227+
None => io::stdin(),
228+
Some(ref path) => io::file_reader(path).get()
229+
};
230230

231231
self.fi.current_reader = Some(file);
232232
self.fi.state.current_path = path_option;
@@ -431,8 +431,8 @@ mod test {
431431
#[test]
432432
fn test_pathify() {
433433
let strs = [~"some/path",
434-
~"some/other/path"],
435-
paths = ~[Some(Path("some/path")),
434+
~"some/other/path"];
435+
let paths = ~[Some(Path("some/path")),
436436
Some(Path("some/other/path"))];
437437

438438
assert_eq!(pathify(strs, true), copy paths);
@@ -561,8 +561,10 @@ mod test {
561561
562562
#[test]
563563
fn test_no_trailing_newline() {
564-
let f1 = Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")),
565-
f2 = Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
564+
let f1 =
565+
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp"));
566+
let f2 =
567+
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
566568
567569
let wr = io::file_writer(f1.get_ref(), [io::Create, io::Truncate]).get();
568570
wr.write_str("1\n2");

src/libextra/md4.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ pub fn md4(msg: &[u8]) -> Quad {
5858
let e = msg.len();
5959
let mut x = vec::from_elem(16u, 0u32);
6060
while i < e {
61-
let aa = a, bb = b, cc = c, dd = d;
61+
let (aa, bb, cc, dd) = (a, b, c, d);
6262

63-
let mut j = 0u, base = i;
63+
let mut (j, base) = (0u, i);
6464
while j < 16u {
6565
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
6666
(msg[base + 2u] as u32 << 16u32) +

src/libextra/net_url.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn get_authority(rawurl: &str) ->
416416
let mut port = None;
417417

418418
let mut colon_count = 0;
419-
let mut pos = 0, begin = 2, end = len;
419+
let mut (pos, begin, end) = (0, 2, len);
420420

421421
for str::each_chari(rawurl) |i,c| {
422422
if i < 2 { loop; } // ignore the leading //

src/libextra/num/bigint.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Ord for BigUint {
125125
impl TotalOrd for BigUint {
126126

127127
fn cmp(&self, other: &BigUint) -> Ordering {
128-
let s_len = self.data.len(), o_len = other.data.len();
128+
let (s_len, o_len) = (self.data.len(), other.data.len());
129129
if s_len < o_len { return Less; }
130130
if s_len > o_len { return Greater; }
131131

@@ -255,7 +255,7 @@ impl Mul<BigUint, BigUint> for BigUint {
255255
fn mul(&self, other: &BigUint) -> BigUint {
256256
if self.is_zero() || other.is_zero() { return Zero::zero(); }
257257

258-
let s_len = self.data.len(), o_len = other.data.len();
258+
let (s_len, o_len) = (self.data.len(), other.data.len());
259259
if s_len == 1 { return mul_digit(other, self.data[0]); }
260260
if o_len == 1 { return mul_digit(self, other.data[0]); }
261261

@@ -447,7 +447,7 @@ impl Integer for BigUint {
447447

448448
fn gcd(&self, other: &BigUint) -> BigUint {
449449
// Use Euclid's algorithm
450-
let mut m = copy *self, n = copy *other;
450+
let mut (m, n) = (copy *self, copy *other);
451451
while !m.is_zero() {
452452
let temp = m;
453453
m = n % temp;
@@ -1002,8 +1002,8 @@ impl Integer for BigInt {
10021002
fn div_mod_floor(&self, other: &BigInt) -> (BigInt, BigInt) {
10031003
// m.sign == other.sign
10041004
let (d_ui, m_ui) = self.data.div_rem(&other.data);
1005-
let d = BigInt::from_biguint(Plus, d_ui),
1006-
m = BigInt::from_biguint(Plus, m_ui);
1005+
let d = BigInt::from_biguint(Plus, d_ui);
1006+
let m = BigInt::from_biguint(Plus, m_ui);
10071007
match (self.sign, other.sign) {
10081008
(_, Zero) => fail!(),
10091009
(Plus, Plus) | (Zero, Plus) => (d, m),

src/libextra/term.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Terminal {
5757
}
5858

5959
#[cfg(not(target_os = "win32"))]
60-
pub impl Terminal {
60+
impl Terminal {
6161
pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
6262
let term = os::getenv("TERM");
6363
if term.is_none() {
@@ -81,7 +81,7 @@ pub impl Terminal {
8181

8282
return Ok(Terminal {out: out, ti: inf, color_supported: cs});
8383
}
84-
fn fg(&self, color: u8) {
84+
pub fn fg(&self, color: u8) {
8585
if self.color_supported {
8686
let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
8787
[Number(color as int)], [], []);
@@ -92,7 +92,7 @@ pub impl Terminal {
9292
}
9393
}
9494
}
95-
fn bg(&self, color: u8) {
95+
pub fn bg(&self, color: u8) {
9696
if self.color_supported {
9797
let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
9898
[Number(color as int)], [], []);
@@ -103,7 +103,7 @@ pub impl Terminal {
103103
}
104104
}
105105
}
106-
fn reset(&self) {
106+
pub fn reset(&self) {
107107
if self.color_supported {
108108
let s = expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []);
109109
if s.is_ok() {
@@ -116,17 +116,17 @@ pub impl Terminal {
116116
}
117117

118118
#[cfg(target_os = "win32")]
119-
pub impl Terminal {
119+
impl Terminal {
120120
pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
121121
return Ok(Terminal {out: out, color_supported: false});
122122
}
123123

124-
fn fg(&self, color: u8) {
124+
pub fn fg(&self, color: u8) {
125125
}
126126

127-
fn bg(&self, color: u8) {
127+
pub fn bg(&self, color: u8) {
128128
}
129129

130-
fn reset(&self) {
130+
pub fn reset(&self) {
131131
}
132132
}

src/libextra/terminfo/parser/compiled.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs
160160

161161
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
162162
pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
163-
let bnames, snames, nnames;
163+
let bnames;
164+
let snames;
165+
let nnames;
164166

165167
if longnames {
166168
bnames = boolfnames;

src/librustc/front/config.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,18 @@ fn fold_block(
140140
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
141141
let filtered_view_items =
142142
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
143+
let filtered_view_items =
144+
filtered_view_items.map(|x| fld.fold_view_item(*x));
145+
let mut resulting_stmts = ~[];
146+
for filtered_stmts.each |stmt| {
147+
match fld.fold_stmt(*stmt) {
148+
None => {}
149+
Some(stmt) => resulting_stmts.push(stmt),
150+
}
151+
}
143152
ast::blk_ {
144-
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
145-
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
153+
view_items: filtered_view_items,
154+
stmts: resulting_stmts,
146155
expr: b.expr.map(|x| fld.fold_expr(*x)),
147156
id: b.id,
148157
rules: b.rules,

src/librustc/middle/check_match.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
380380
}
381381
ty::ty_nil => None,
382382
ty::ty_bool => {
383-
let mut true_found = false, false_found = false;
383+
let mut true_found = false;
384+
let mut false_found = false;
384385
for m.each |r| {
385386
match pat_ctor_id(cx, r[0]) {
386387
None => (),
@@ -513,10 +514,12 @@ pub fn specialize(cx: @MatchCheckCtxt,
513514
}
514515
},
515516
range(ref c_lo, ref c_hi) => {
516-
let m1 = compare_const_vals(c_lo, &e_v),
517-
m2 = compare_const_vals(c_hi, &e_v);
517+
let m1 = compare_const_vals(c_lo, &e_v);
518+
let m2 = compare_const_vals(c_hi, &e_v);
518519
match (m1, m2) {
519-
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
520+
(Some(val1), Some(val2)) => {
521+
(val1 >= 0 && val2 <= 0)
522+
}
520523
_ => {
521524
cx.tcx.sess.span_err(pat_span,
522525
"mismatched types between ranges");
@@ -560,8 +563,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
560563
}
561564
},
562565
range(ref c_lo, ref c_hi) => {
563-
let m1 = compare_const_vals(c_lo, &e_v),
564-
m2 = compare_const_vals(c_hi, &e_v);
566+
let m1 = compare_const_vals(c_lo, &e_v);
567+
let m2 = compare_const_vals(c_hi, &e_v);
565568
match (m1, m2) {
566569
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
567570
_ => {
@@ -622,7 +625,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
622625
}
623626
_ => {
624627
// Grab the class data that we care about.
625-
let class_fields, class_id;
628+
let class_fields;
629+
let class_id;
626630
match ty::get(left_ty).sty {
627631
ty::ty_struct(cid, _) => {
628632
class_id = cid;
@@ -667,8 +671,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
667671
}
668672
},
669673
range(ref c_lo, ref c_hi) => {
670-
let m1 = compare_const_vals(c_lo, &e_v),
671-
m2 = compare_const_vals(c_hi, &e_v);
674+
let m1 = compare_const_vals(c_lo, &e_v);
675+
let m2 = compare_const_vals(c_hi, &e_v);
672676
match (m1, m2) {
673677
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
674678
_ => {
@@ -691,11 +695,11 @@ pub fn specialize(cx: @MatchCheckCtxt,
691695
single => return Some(vec::to_owned(r.tail())),
692696
_ => fail!("type error")
693697
};
694-
let v_lo = eval_const_expr(cx.tcx, lo),
695-
v_hi = eval_const_expr(cx.tcx, hi);
698+
let v_lo = eval_const_expr(cx.tcx, lo);
699+
let v_hi = eval_const_expr(cx.tcx, hi);
696700

697-
let m1 = compare_const_vals(&c_lo, &v_lo),
698-
m2 = compare_const_vals(&c_hi, &v_hi);
701+
let m1 = compare_const_vals(&c_lo, &v_lo);
702+
let m2 = compare_const_vals(&c_hi, &v_hi);
699703
match (m1, m2) {
700704
(Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => {
701705
Some(vec::to_owned(r.tail()))

src/librustc/middle/dataflow.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,9 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
372372
in_out: &mut [uint],
373373
loop_scopes: &mut ~[LoopScope]) {
374374
match decl.node {
375-
ast::decl_local(ref locals) => {
376-
for locals.each |local| {
377-
self.walk_pat(local.node.pat, in_out, loop_scopes);
378-
self.walk_opt_expr(local.node.init, in_out, loop_scopes);
379-
}
375+
ast::decl_local(local) => {
376+
self.walk_pat(local.node.pat, in_out, loop_scopes);
377+
self.walk_opt_expr(local.node.init, in_out, loop_scopes);
380378
}
381379

382380
ast::decl_item(_) => {}

src/librustc/middle/liveness.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,10 @@ impl Liveness {
948948
pub fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
949949
-> LiveNode {
950950
match decl.node {
951-
decl_local(ref locals) => {
952-
do locals.foldr(succ) |local, succ| {
951+
decl_local(ref local) => {
953952
self.propagate_through_local(*local, succ)
954953
}
955-
}
956-
decl_item(_) => {
957-
succ
958-
}
954+
decl_item(_) => succ,
959955
}
960956
}
961957

0 commit comments

Comments
 (0)