Skip to content

Commit 4af52ee

Browse files
committed
Repair various cases where values of distinct types were being operated
upon (e.g., `&int` added to `int`).
1 parent 98958bc commit 4af52ee

File tree

10 files changed

+56
-15
lines changed

10 files changed

+56
-15
lines changed

src/libarena/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Drop for Arena {
132132

133133
#[inline]
134134
fn round_up(base: uint, align: uint) -> uint {
135-
(base.checked_add(&(align - 1))).unwrap() & !(&(align - 1))
135+
(base.checked_add(&(align - 1))).unwrap() & !(align - 1)
136136
}
137137

138138
// Walk down a chunk, running the destructors for any objects stored

src/libcollections/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl<T> Vec<T> {
919919
///
920920
/// ```
921921
/// let mut vec = vec![1i, 2, 3, 4];
922-
/// vec.retain(|x| x%2 == 0);
922+
/// vec.retain(|&x| x%2 == 0);
923923
/// assert_eq!(vec, vec![2, 4]);
924924
/// ```
925925
#[unstable = "the closure argument may become an unboxed closure"]

src/libcore/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
787787
/// use std::uint;
788788
///
789789
/// let v = vec!(1u, 2u);
790-
/// let res: Option<Vec<uint>> = v.iter().map(|x: &uint|
791-
/// if *x == uint::MAX { None }
790+
/// let res: Option<Vec<uint>> = v.iter().map(|&x: &uint|
791+
/// if x == uint::MAX { None }
792792
/// else { Some(x + 1) }
793793
/// ).collect();
794794
/// assert!(res == Some(vec!(2u, 3u)));

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
894894
/// use std::uint;
895895
///
896896
/// let v = vec!(1u, 2u);
897-
/// let res: Result<Vec<uint>, &'static str> = v.iter().map(|x: &uint|
898-
/// if *x == uint::MAX { Err("Overflow!") }
897+
/// let res: Result<Vec<uint>, &'static str> = v.iter().map(|&x: &uint|
898+
/// if x == uint::MAX { Err("Overflow!") }
899899
/// else { Ok(x + 1) }
900900
/// ).collect();
901901
/// assert!(res == Ok(vec!(2u, 3u)));

src/libcoretest/iter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ fn test_iterator_size_hint() {
356356
assert_eq!(vi.zip(v2.iter()).size_hint(), (3, Some(3)));
357357
assert_eq!(vi.scan(0i, |_,_| Some(0i)).size_hint(), (0, Some(10)));
358358
assert_eq!(vi.filter(|_| false).size_hint(), (0, Some(10)));
359-
assert_eq!(vi.map(|i| i+1).size_hint(), (10, Some(10)));
359+
assert_eq!(vi.map(|&i| i+1).size_hint(), (10, Some(10)));
360360
assert_eq!(vi.filter_map(|_| Some(0i)).size_hint(), (0, Some(10)));
361361
}
362362

@@ -388,9 +388,9 @@ fn test_any() {
388388
#[test]
389389
fn test_find() {
390390
let v: &[int] = &[1i, 3, 9, 27, 103, 14, 11];
391-
assert_eq!(*v.iter().find(|x| *x & 1 == 0).unwrap(), 14);
392-
assert_eq!(*v.iter().find(|x| *x % 3 == 0).unwrap(), 3);
393-
assert!(v.iter().find(|x| *x % 12 == 0).is_none());
391+
assert_eq!(*v.iter().find(|&&x| x & 1 == 0).unwrap(), 14);
392+
assert_eq!(*v.iter().find(|&&x| x % 3 == 0).unwrap(), 3);
393+
assert!(v.iter().find(|&&x| x % 12 == 0).is_none());
394394
}
395395

396396
#[test]

src/libstd/bitflags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ macro_rules! bitflags {
177177
/// Returns `true` if there are flags common to both `self` and `other`.
178178
#[inline]
179179
pub fn intersects(&self, other: $BitFlags) -> bool {
180-
!(self & other).is_empty()
180+
!(*self & other).is_empty()
181181
}
182182

183183
/// Returns `true` all of the flags in `other` are contained within `self`.
184184
#[inline]
185185
pub fn contains(&self, other: $BitFlags) -> bool {
186-
(self & other) == other
186+
(*self & other) == other
187187
}
188188

189189
/// Inserts the specified flags in-place.

src/libstd/time/duration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl fmt::Show for Duration {
319319
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
320320
// technically speaking, negative duration is not valid ISO 8601,
321321
// but we need to print it anyway.
322-
let (abs, sign) = if self.secs < 0 { (-self, "-") } else { (*self, "") };
322+
let (abs, sign) = if self.secs < 0 { (-*self, "-") } else { (*self, "") };
323323

324324
let days = abs.secs / SECS_PER_DAY;
325325
let secs = abs.secs - days * SECS_PER_DAY;

src/libtime/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Add<Duration, Timespec> for Timespec {
9696
let d_sec = other.num_seconds();
9797
// It is safe to unwrap the nanoseconds, because there cannot be
9898
// more than one second left, which fits in i64 and in i32.
99-
let d_nsec = (other - Duration::seconds(d_sec))
99+
let d_nsec = (*other - Duration::seconds(d_sec))
100100
.num_nanoseconds().unwrap() as i32;
101101
let mut sec = self.sec + d_sec;
102102
let mut nsec = self.nsec + d_nsec;

src/test/bench/shootout-meteor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn search(
290290
let masks_at = &masks[i];
291291

292292
// for every unused piece
293-
for id in range(0u, 10).filter(|id| board & (1 << (id + 50)) == 0) {
293+
for id in range(0u, 10).filter(|&id| board & (1 << (id + 50)) == 0) {
294294
// for each mask that fits on the board
295295
for m in masks_at[id].iter().filter(|&m| board & *m == 0) {
296296
// This check is too costly.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we can overload the `+` operator for points so that two
12+
// points can be added, and a point can be added to an integer.
13+
14+
use std::ops;
15+
16+
#[deriving(Show,PartialEq,Eq)]
17+
struct Point {
18+
x: int,
19+
y: int
20+
}
21+
22+
impl ops::Add<Point,Point> for Point {
23+
fn add(&self, other: &Point) -> Point {
24+
Point {x: self.x + (*other).x, y: self.y + (*other).y}
25+
}
26+
}
27+
28+
impl ops::Add<int,Point> for Point {
29+
fn add(&self, &other: &int) -> Point {
30+
Point {x: self.x + other,
31+
y: self.y + other}
32+
}
33+
}
34+
35+
pub fn main() {
36+
let mut p = Point {x: 10, y: 20};
37+
p = p + Point {x: 101, y: 102};
38+
assert_eq!(p, Point {x: 111, y: 122});
39+
p = p + 1;
40+
assert_eq!(p, Point {x: 112, y: 123});
41+
}

0 commit comments

Comments
 (0)