From 7d72719efc25c6cdb8963c187e93df646ba65245 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 7 Jan 2015 19:26:00 -0500 Subject: [PATCH] fix the `&mut _` patterns --- src/libcollections/vec.rs | 2 +- src/libcore/iter.rs | 2 +- src/libcore/option.rs | 2 +- src/libcore/result.rs | 6 +++--- src/libcoretest/any.rs | 4 ++-- src/librustc_driver/pretty.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/libstd/sync/mpsc/stream.rs | 6 +++--- src/libsyntax/ast_map/mod.rs | 2 +- src/test/bench/shootout-meteor.rs | 2 +- src/test/compile-fail/issue-15756.rs | 2 +- src/test/compile-fail/mut-pattern-mismatched.rs | 2 +- src/test/compile-fail/pattern-bindings-after-at.rs | 2 +- src/test/run-pass/drop-trait-enum.rs | 6 +++--- src/test/run-pass/issue-16774.rs | 2 +- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 04a2d5b5bc9..2cff9b2cb92 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2030,7 +2030,7 @@ mod tests { v.push(()); assert_eq!(v.iter_mut().count(), 4); - for &() in v.iter_mut() {} + for &mut () in v.iter_mut() {} unsafe { v.set_len(0); } assert_eq!(v.iter_mut().count(), 0); } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index d30cfc405a1..87d61358ed3 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2344,7 +2344,7 @@ impl RandomAccessIterator for Inspect where /// /// // This iterator will yield up to the last Fibonacci number before the max value of `u32`. /// // You can simply change `u32` to `u64` in this line if you want higher values than that. -/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), |&(ref mut x2, ref mut x1)| { +/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), |&mut (ref mut x2, ref mut x1)| { /// // Attempt to get the next Fibonacci number /// // `x1` will be `None` if previously overflowed. /// let next = match (*x2, *x1) { diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 272570a0d5b..108cbadcc17 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -533,7 +533,7 @@ impl Option { /// ``` /// let mut x = Some(4u); /// match x.iter_mut().next() { - /// Some(&ref mut v) => *v = 42u, + /// Some(&mut ref mut v) => *v = 42u, /// None => {}, /// } /// assert_eq!(x, Some(42)); diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 95ae6ebfb68..7868ec67c8a 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -383,8 +383,8 @@ impl Result { /// ``` /// fn mutate(r: &mut Result) { /// match r.as_mut() { - /// Ok(&ref mut v) => *v = 42, - /// Err(&ref mut e) => *e = 0, + /// Ok(&mut ref mut v) => *v = 42, + /// Err(&mut ref mut e) => *e = 0, /// } /// } /// @@ -529,7 +529,7 @@ impl Result { /// ``` /// let mut x: Result = Ok(7); /// match x.iter_mut().next() { - /// Some(&ref mut x) => *x = 40, + /// Some(&mut ref mut x) => *x = 40, /// None => {}, /// } /// assert_eq!(x, Ok(40)); diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs index c0be3a28794..e6a7170acea 100644 --- a/src/libcoretest/any.rs +++ b/src/libcoretest/any.rs @@ -101,12 +101,12 @@ fn any_downcast_mut() { } match a_r.downcast_mut::() { - Some(&612) => {} + Some(&mut 612) => {} x => panic!("Unexpected value {:?}", x) } match b_r.downcast_mut::() { - Some(&413) => {} + Some(&mut 413) => {} x => panic!("Unexpected value {:?}", x) } } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index c090ba033a7..7592fbc05b3 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -350,8 +350,8 @@ impl<'a, 'ast> Iterator for NodesMatchingUII<'a, 'ast> { fn next(&mut self) -> Option { match self { - &NodesMatchingDirect(ref mut iter) => iter.next(), - &NodesMatchingSuffix(ref mut iter) => iter.next(), + &mut NodesMatchingDirect(ref mut iter) => iter.next(), + &mut NodesMatchingSuffix(ref mut iter) => iter.next(), } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c2bad39b78b..2b7f615dc12 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1709,7 +1709,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64. pub fn default_type_parameters(&self) { use middle::ty::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat, Neither}; - for (_, &ref ty) in self.inh.node_types.borrow_mut().iter_mut() { + for (_, &mut ref ty) in self.inh.node_types.borrow_mut().iter_mut() { let resolved = self.infcx().resolve_type_vars_if_possible(ty); if self.infcx().type_var_diverges(resolved) { demand::eqtype(self, codemap::DUMMY_SP, *ty, ty::mk_nil(self.tcx())); diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index bd1e74a3390..f4b20c7b742 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -338,7 +338,7 @@ impl Packet { // upgrade pending, then go through the whole recv rigamarole to update // the internal state. match self.queue.peek() { - Some(&GoUp(..)) => { + Some(&mut GoUp(..)) => { match self.recv() { Err(Upgraded(port)) => Err(port), _ => unreachable!(), @@ -367,7 +367,7 @@ impl Packet { Ok(()) => SelSuccess, Err(token) => { let ret = match self.queue.peek() { - Some(&GoUp(..)) => { + Some(&mut GoUp(..)) => { match self.queue.pop() { Some(GoUp(port)) => SelUpgraded(token, port), _ => unreachable!(), @@ -457,7 +457,7 @@ impl Packet { // upgraded port. if has_data { match self.queue.peek() { - Some(&GoUp(..)) => { + Some(&mut GoUp(..)) => { match self.queue.pop() { Some(GoUp(port)) => Err(port), _ => unreachable!(), diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index adcb9ff9cc2..e6f2979a3f8 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -90,7 +90,7 @@ impl<'a, T: Copy> Iterator for Values<'a, T> { type Item = T; fn next(&mut self) -> Option { - let &Values(ref mut items) = self; + let &mut Values(ref mut items) = self; items.next().map(|&x| x) } } diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 34a036eff37..0480c9d884a 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -118,7 +118,7 @@ fn transform(piece: Vec<(int, int)> , all: bool) -> Vec> { // translating to (0, 0) as minimum coordinates. for cur_piece in res.iter_mut() { let (dy, dx) = *cur_piece.iter().min_by(|e| *e).unwrap(); - for &(ref mut y, ref mut x) in cur_piece.iter_mut() { + for &mut (ref mut y, ref mut x) in cur_piece.iter_mut() { *y -= dy; *x -= dx; } } diff --git a/src/test/compile-fail/issue-15756.rs b/src/test/compile-fail/issue-15756.rs index c2d30224dc8..02ccf9c0e08 100644 --- a/src/test/compile-fail/issue-15756.rs +++ b/src/test/compile-fail/issue-15756.rs @@ -14,7 +14,7 @@ use std::slice::ChunksMut; fn dft_iter<'a, T>(arg1: Chunks<'a,T>, arg2: ChunksMut<'a,T>) { for - &something + &mut something //~^ ERROR the trait `core::marker::Sized` is not implemented for the type `[T]` in arg2 { diff --git a/src/test/compile-fail/mut-pattern-mismatched.rs b/src/test/compile-fail/mut-pattern-mismatched.rs index 714fbd08281..9f1d3d1fb39 100644 --- a/src/test/compile-fail/mut-pattern-mismatched.rs +++ b/src/test/compile-fail/mut-pattern-mismatched.rs @@ -13,7 +13,7 @@ fn main() { // (separate lines to ensure the spans are accurate) - let &_ // ~ ERROR expected `&mut isize`, found `&_` + let &_ //~ ERROR expected `&mut isize`, found `&_` = foo; let &mut _ = foo; diff --git a/src/test/compile-fail/pattern-bindings-after-at.rs b/src/test/compile-fail/pattern-bindings-after-at.rs index 9cd2d0d28b1..54ac3cba636 100644 --- a/src/test/compile-fail/pattern-bindings-after-at.rs +++ b/src/test/compile-fail/pattern-bindings-after-at.rs @@ -15,7 +15,7 @@ enum Option { fn main() { match &mut Some(1i) { - ref mut z @ &Some(ref a) => { + ref mut z @ &mut Some(ref a) => { //~^ ERROR pattern bindings are not allowed after an `@` **z = None; println!("{}", *a); diff --git a/src/test/run-pass/drop-trait-enum.rs b/src/test/run-pass/drop-trait-enum.rs index f1cc4fb1724..4c7b0680621 100644 --- a/src/test/run-pass/drop-trait-enum.rs +++ b/src/test/run-pass/drop-trait-enum.rs @@ -36,13 +36,13 @@ enum Foo { impl Drop for Foo { fn drop(&mut self) { match self { - &Foo::SimpleVariant(ref mut sender) => { + &mut Foo::SimpleVariant(ref mut sender) => { sender.send(Message::DestructorRan).unwrap(); } - &Foo::NestedVariant(_, _, ref mut sender) => { + &mut Foo::NestedVariant(_, _, ref mut sender) => { sender.send(Message::DestructorRan).unwrap(); } - &Foo::FailingVariant { .. } => { + &mut Foo::FailingVariant { .. } => { panic!("Failed"); } } diff --git a/src/test/run-pass/issue-16774.rs b/src/test/run-pass/issue-16774.rs index 6ef4f868d21..4246fced26c 100644 --- a/src/test/run-pass/issue-16774.rs +++ b/src/test/run-pass/issue-16774.rs @@ -36,7 +36,7 @@ impl Deref for X { impl DerefMut for X { fn deref_mut(&mut self) -> &mut int { - let &X(box ref mut x) = self; + let &mut X(box ref mut x) = self; x } }