diff options
| author | kennytm <kennytm@gmail.com> | 2018-03-28 03:03:39 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-03-28 03:03:39 +0800 |
| commit | 605ea7c31f7341995c2d1ae12b4b33fe6bd908b5 (patch) | |
| tree | 19b13ac2494f1e1b347ee8aae9c48150677434f3 /src/libstd | |
| parent | 19fe9d1181bb15f76cdf2b5335edff5a82c5152b (diff) | |
| parent | f513fbdf36ad0708fb222b8d55bc086dd4be18cf (diff) | |
| download | rust-605ea7c31f7341995c2d1ae12b4b33fe6bd908b5.tar.gz rust-605ea7c31f7341995c2d1ae12b4b33fe6bd908b5.zip | |
Rollup merge of #49426 - lukaslueg:patch-1, r=kennytm
Update CONTRIBUTING.md The current link is a 404, just link to the main repo page
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/error.rs | 6 | ||||
| -rw-r--r-- | src/libstd/io/cursor.rs | 20 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/prelude/v1.rs | 2 |
4 files changed, 23 insertions, 6 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 79bb6af168f..3d0c96585b5 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -275,14 +275,14 @@ impl Error for num::ParseIntError { } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.26.0")] impl Error for num::TryFromIntError { fn description(&self) -> &str { self.__description() } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.26.0")] impl Error for array::TryFromSliceError { fn description(&self) -> &str { self.__description() @@ -356,7 +356,7 @@ impl Error for cell::BorrowMutError { } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.26.0")] impl Error for char::CharTryFromError { fn description(&self) -> &str { "converted integer out of range for `char`" 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") })?; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 93996868f16..15a22443b6a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -310,7 +310,6 @@ #![feature(test, rustc_private)] #![feature(thread_local)] #![feature(toowned_clone_into)] -#![feature(try_from)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(unicode)] diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs index feedd4e1abe..d5b7c68a3fa 100644 --- a/src/libstd/prelude/v1.rs +++ b/src/libstd/prelude/v1.rs @@ -35,6 +35,8 @@ #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use convert::{AsRef, AsMut, Into, From}; +#[stable(feature = "try_from", since = "1.26.0")] +#[doc(no_inline)] pub use convert::{TryFrom, TryInto}; #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use default::Default; #[stable(feature = "rust1", since = "1.0.0")] |
