about summary refs log tree commit diff
path: root/src/libstd/io/extensions.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-17 11:22:00 +0000
committerbors <bors@rust-lang.org>2014-11-17 11:22:00 +0000
commit0047dbe59c41b951d34ce6324f3a8c0e15d523e9 (patch)
treee4f717adb4830ca6e737a23c81abbab3bb3a80b5 /src/libstd/io/extensions.rs
parentedfb83c9e28df2a8f326d688f3d5b1f6faa72db8 (diff)
parentca08540a0039e827114752d11166ea8cb1387068 (diff)
downloadrust-0047dbe59c41b951d34ce6324f3a8c0e15d523e9.tar.gz
rust-0047dbe59c41b951d34ce6324f3a8c0e15d523e9.zip
auto merge of #19027 : nick29581/rust/coercions-4, r=alexcrichton
The forwards compatible parts of #18645, rebased. Converts implicit coercions from `[T, ..n]` to `&[T]` into explicit references.
Diffstat (limited to 'src/libstd/io/extensions.rs')
-rw-r--r--src/libstd/io/extensions.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs
index 07aa25bc044..70bf90eef93 100644
--- a/src/libstd/io/extensions.rs
+++ b/src/libstd/io/extensions.rs
@@ -82,9 +82,9 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
     assert!(size <= 8u);
     match size {
       1u => f(&[n as u8]),
-      2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_le()) }),
-      4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_le()) }),
-      8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_le()) }),
+      2u => f(unsafe { & transmute::<_, [u8, ..2]>((n as u16).to_le()) }),
+      4u => f(unsafe { & transmute::<_, [u8, ..4]>((n as u32).to_le()) }),
+      8u => f(unsafe { & transmute::<_, [u8, ..8]>(n.to_le()) }),
       _ => {
 
         let mut bytes = vec!();
@@ -121,9 +121,9 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
     assert!(size <= 8u);
     match size {
       1u => f(&[n as u8]),
-      2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_be()) }),
-      4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_be()) }),
-      8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_be()) }),
+      2u => f(unsafe { & transmute::<_, [u8, ..2]>((n as u16).to_be()) }),
+      4u => f(unsafe { & transmute::<_, [u8, ..4]>((n as u32).to_be()) }),
+      8u => f(unsafe { & transmute::<_, [u8, ..8]>(n.to_be()) }),
       _ => {
         let mut bytes = vec!();
         let mut i = size;
@@ -474,26 +474,26 @@ mod test {
         let buf = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09];
 
         // Aligned access
-        assert_eq!(u64_from_be_bytes(buf, 0, 0), 0);
-        assert_eq!(u64_from_be_bytes(buf, 0, 1), 0x01);
-        assert_eq!(u64_from_be_bytes(buf, 0, 2), 0x0102);
-        assert_eq!(u64_from_be_bytes(buf, 0, 3), 0x010203);
-        assert_eq!(u64_from_be_bytes(buf, 0, 4), 0x01020304);
-        assert_eq!(u64_from_be_bytes(buf, 0, 5), 0x0102030405);
-        assert_eq!(u64_from_be_bytes(buf, 0, 6), 0x010203040506);
-        assert_eq!(u64_from_be_bytes(buf, 0, 7), 0x01020304050607);
-        assert_eq!(u64_from_be_bytes(buf, 0, 8), 0x0102030405060708);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 0), 0);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 1), 0x01);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 2), 0x0102);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 3), 0x010203);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 4), 0x01020304);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 5), 0x0102030405);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 6), 0x010203040506);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 7), 0x01020304050607);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 8), 0x0102030405060708);
 
         // Unaligned access
-        assert_eq!(u64_from_be_bytes(buf, 1, 0), 0);
-        assert_eq!(u64_from_be_bytes(buf, 1, 1), 0x02);
-        assert_eq!(u64_from_be_bytes(buf, 1, 2), 0x0203);
-        assert_eq!(u64_from_be_bytes(buf, 1, 3), 0x020304);
-        assert_eq!(u64_from_be_bytes(buf, 1, 4), 0x02030405);
-        assert_eq!(u64_from_be_bytes(buf, 1, 5), 0x0203040506);
-        assert_eq!(u64_from_be_bytes(buf, 1, 6), 0x020304050607);
-        assert_eq!(u64_from_be_bytes(buf, 1, 7), 0x02030405060708);
-        assert_eq!(u64_from_be_bytes(buf, 1, 8), 0x0203040506070809);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 0), 0);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 1), 0x02);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 2), 0x0203);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 3), 0x020304);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 4), 0x02030405);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 5), 0x0203040506);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 6), 0x020304050607);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 7), 0x02030405060708);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 8), 0x0203040506070809);
     }
 }