diff options
| author | bors <bors@rust-lang.org> | 2018-03-27 11:50:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-27 11:50:10 +0000 |
| commit | 3efe61c825e1d49dc6febeb252954b9532c0c677 (patch) | |
| tree | 344ae0b1c79ccf598fde261fce7fa23bf56f7cb8 /src/libstd_unicode | |
| parent | 14ac1b5faab32d268a85dfde6c6592b7183c5864 (diff) | |
| parent | 837d6c70233715a0ae8e15c703d40e3046a2f36a (diff) | |
| download | rust-3efe61c825e1d49dc6febeb252954b9532c0c677.tar.gz rust-3efe61c825e1d49dc6febeb252954b9532c0c677.zip | |
Auto merge of #49305 - SimonSapin:fallible, r=sfackler
Stabilize TryFrom / TryInto, and tweak impls for integers Fixes https://github.com/rust-lang/rust/issues/33417 (tracking issue) ---- This adds: * `impl From<u16> for usize` * `impl From<i16> for isize` * `impl From<u8> for isize` … replacing corresponding `TryFrom<Error=!>` impls. (`TryFrom` still applies through the generic `impl<T, U> TryFrom<U> for T where T: From<U>`.) Their infallibility is supported by the C99 standard which (indirectly) requires pointers to be at least 16 bits. The remaining `TryFrom` impls that define `type Error = !` all involve `usize` or `isize`. This PR changes them to use `TryFromIntError` instead, since having a return type change based on the target is a portability hazard. Note: if we make similar assumptions about the *maximum* bit size of pointers (for all targets Rust will ever run on in the future), we could have similar `From` impls converting pointer-sized integers to large fixed-size integers. RISC-V considers the possibility of a 128-bit address space (RV128), which would leave only `impl From<usize> for u128` and `impl From<isize> for u128`. I [found](https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf) some [things](http://www.csl.sri.com/users/neumann/2012resolve-cheri.pdf) about 256-bit “capabilities”, but I don’t know how relevant that would be to Rust’s `usize` and `isize` types. I chose conservatively to make no assumption about the future there. Users making their portability decisions and using something like `.try_into().unwrap()`. ---- Since this feature already went through FCP in the tracking issue https://github.com/rust-lang/rust/issues/33417, this PR also proposes **stabilize** the following items: * The `convert::TryFrom` trait * The `convert::TryFrom` trait * `impl<T> TryFrom<&[T]> for &[T; $N]` (for `$N` up to 32) * `impl<T> TryFrom<&mut [T]> for &mut [T; $N]` (for `$N` up to 32) * The `array::TryFromSliceError` struct, with impls of `Debug`, `Copy`, `Clone`, and `Error` * `impl TryFrom<u32> for char` * The `char::CharTryFromError` struct, with impls of `Copy`, `Clone`, `Debug`, `PartialEq`, `Eq`, `Display`, and `Error` * Impls of `TryFrom` for all (?) combinations of primitive integer types where `From` isn’t implemented. * The `num::TryFromIntError` struct, with impls of `Debug`, `Copy`, `Clone`, `Display`, `From<!>`, and `Error` Some minor remaining questions that I hope can be resolved in this PR: * Should the impls for error types be unified? * ~Should `TryFrom` and `TryInto` be in the prelude? `From` and `Into` are.~ (Yes.)
Diffstat (limited to 'src/libstd_unicode')
| -rw-r--r-- | src/libstd_unicode/char.rs | 2 | ||||
| -rw-r--r-- | src/libstd_unicode/lib.rs | 1 |
2 files changed, 1 insertions, 2 deletions
diff --git a/src/libstd_unicode/char.rs b/src/libstd_unicode/char.rs index de8b46d5f1b..33e47ade8cb 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libstd_unicode/char.rs @@ -42,7 +42,7 @@ pub use core::char::{EscapeDebug, EscapeDefault, EscapeUnicode}; pub use core::char::ParseCharError; // unstable re-exports -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.26.0")] pub use core::char::CharTryFromError; #[unstable(feature = "decode_utf8", issue = "33906")] pub use core::char::{DecodeUtf8, decode_utf8}; diff --git a/src/libstd_unicode/lib.rs b/src/libstd_unicode/lib.rs index f155b62e3cc..c22ea1671fa 100644 --- a/src/libstd_unicode/lib.rs +++ b/src/libstd_unicode/lib.rs @@ -39,7 +39,6 @@ #![feature(lang_items)] #![feature(non_exhaustive)] #![feature(staged_api)] -#![feature(try_from)] #![feature(unboxed_closures)] mod bool_trie; |
