about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-03-26 22:48:12 +0200
committerSimon Sapin <simon.sapin@exyr.org>2018-03-27 09:48:42 +0200
commit837d6c70233715a0ae8e15c703d40e3046a2f36a (patch)
tree5d3149e0f2799ebee51f07fc6e0b862d2834de6f /src/libstd/io
parent09008cc23ff6395c2c928f3690e07d7389d08ebc (diff)
downloadrust-837d6c70233715a0ae8e15c703d40e3046a2f36a.tar.gz
rust-837d6c70233715a0ae8e15c703d40e3046a2f36a.zip
Remove TryFrom impls that might become conditionally-infallible with a portability lint
https://github.com/rust-lang/rust/pull/49305#issuecomment-376293243
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/cursor.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs
index 76bcb5fedc9..2673f3ccfa3 100644
--- a/src/libstd/io/cursor.rs
+++ b/src/libstd/io/cursor.rs
@@ -10,7 +10,6 @@
 
 use io::prelude::*;
 
-use core::convert::TryInto;
 use cmp;
 use io::{self, Initializer, SeekFrom, Error, ErrorKind};
 
@@ -260,9 +259,26 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result<us
     Ok(amt)
 }
 
+/// Compensate removal of some impls per
+/// https://github.com/rust-lang/rust/pull/49305#issuecomment-376293243
+#[cfg(any(target_pointer_width = "16",
+          target_pointer_width = "32"))]
+fn try_into(n: u64) -> Result<usize, ()> {
+    if n <= (<usize>::max_value() as u64) {
+        Ok(n as usize)
+    } else {
+        Err(())
+    }
+}
+
+#[cfg(any(target_pointer_width = "64"))]
+fn try_into(n: u64) -> Result<usize, ()> {
+    Ok(n as usize)
+}
+
 // Resizing write implementation
 fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
-    let pos: usize = (*pos_mut).try_into().map_err(|_| {
+    let pos: usize = try_into(*pos_mut).map_err(|_| {
         Error::new(ErrorKind::InvalidInput,
                     "cursor position exceeds maximum possible vector length")
     })?;