]> git.lizzy.rs Git - rust.git/commitdiff
Step::replace_one should put a one, not a zero (Issue #41492)
authorScott McMurray <scottmcm@users.noreply.github.com>
Mon, 24 Apr 2017 04:47:09 +0000 (21:47 -0700)
committerScott McMurray <scottmcm@users.noreply.github.com>
Mon, 24 Apr 2017 04:47:09 +0000 (21:47 -0700)
Turns out all six of these impls are incorrect.

src/libcore/iter/range.rs
src/libcore/tests/iter.rs
src/libcore/tests/lib.rs

index 687c477f19e4c744aff29905f0fd43973fd6cb3d..bd831d638c0c4cc24e8573501345ab809c489477 100644 (file)
@@ -86,12 +86,12 @@ fn is_negative(&self) -> bool {
 
             #[inline]
             fn replace_one(&mut self) -> Self {
-                mem::replace(self, 0)
+                mem::replace(self, 1)
             }
 
             #[inline]
             fn replace_zero(&mut self) -> Self {
-                mem::replace(self, 1)
+                mem::replace(self, 0)
             }
 
             #[inline]
@@ -157,12 +157,12 @@ fn is_negative(&self) -> bool {
 
             #[inline]
             fn replace_one(&mut self) -> Self {
-                mem::replace(self, 0)
+                mem::replace(self, 1)
             }
 
             #[inline]
             fn replace_zero(&mut self) -> Self {
-                mem::replace(self, 1)
+                mem::replace(self, 0)
             }
 
             #[inline]
@@ -206,12 +206,12 @@ fn is_negative(&self) -> bool {
 
             #[inline]
             fn replace_one(&mut self) -> Self {
-                mem::replace(self, 0)
+                mem::replace(self, 1)
             }
 
             #[inline]
             fn replace_zero(&mut self) -> Self {
-                mem::replace(self, 1)
+                mem::replace(self, 0)
             }
 
             #[inline]
index 08442f9bcbff522d498b826d3dda8d1faf1b011e..001fa304cd08f5185c7c812a70add563f92cc5d6 100644 (file)
@@ -1082,3 +1082,41 @@ fn test_chain_fold() {
     assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
 }
 
+#[test]
+fn test_step_replace_unsigned() {
+    let mut x = 4u32;
+    let y = x.replace_zero();
+    assert_eq!(x, 0);
+    assert_eq!(y, 4);
+
+    x = 5;
+    let y = x.replace_one();
+    assert_eq!(x, 1);
+    assert_eq!(y, 5);
+}
+
+#[test]
+fn test_step_replace_signed() {
+    let mut x = 4i32;
+    let y = x.replace_zero();
+    assert_eq!(x, 0);
+    assert_eq!(y, 4);
+
+    x = 5;
+    let y = x.replace_one();
+    assert_eq!(x, 1);
+    assert_eq!(y, 5);
+}
+
+#[test]
+fn test_step_replace_no_between() {
+    let mut x = 4u128;
+    let y = x.replace_zero();
+    assert_eq!(x, 0);
+    assert_eq!(y, 4);
+
+    x = 5;
+    let y = x.replace_one();
+    assert_eq!(x, 1);
+    assert_eq!(y, 5);
+}
\ No newline at end of file
index 528ab3bc84523e184ee7b41b12bbce7d9e36ee57..f0c46a6f194d55b5654f0fa2d78047cc3e4975ea 100644 (file)
@@ -20,6 +20,7 @@
 #![feature(fixed_size_array)]
 #![feature(flt2dec)]
 #![feature(fmt_internals)]
+#![feature(i128_type)]
 #![feature(iter_rfind)]
 #![feature(libc)]
 #![feature(nonzero)]
@@ -30,6 +31,7 @@
 #![feature(sort_internals)]
 #![feature(sort_unstable)]
 #![feature(step_by)]
+#![feature(step_trait)]
 #![feature(test)]
 #![feature(try_from)]
 #![feature(unicode)]