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/rustllvm/RustWrapper.cpp | |
| 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/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
