rust/src/test
bors 3efe61c825 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.)
2018-03-27 11:50:10 +00:00
..
auxiliary
codegen Auto merge of #49249 - gnzlbg:simd_minmax, r=alexcrichton 2018-03-27 04:46:32 +00:00
codegen-units
compile-fail Remove library feature test 2018-03-26 08:37:56 -05:00
compile-fail-fulldeps
debuginfo
incremental Stabilize conservative_impl_trait 2018-03-26 10:43:03 +02:00
incremental-fulldeps
mir-opt Stabilize i128_type 2018-03-26 08:36:50 -05:00
parse-fail
pretty
run-fail fix tests 2018-03-26 10:20:41 +02:00
run-fail-fulldeps
run-make pgo: Move the tests to run-make-fulldeps, and make the profile file be in the tmp directory properly. 2018-03-25 03:58:26 +02:00
run-make-fulldeps pgo: Move the tests to run-make-fulldeps, and make the profile file be in the tmp directory properly. 2018-03-25 03:58:26 +02:00
run-pass Fix missed i128 feature gates 2018-03-26 08:37:56 -05:00
run-pass-fulldeps
run-pass-valgrind
rustdoc Stabilize conservative_impl_trait 2018-03-26 10:43:03 +02:00
rustdoc-js
ui Stabilize the TryFrom and TryInto traits 2018-03-26 23:36:02 +02:00
ui-fulldeps
COMPILER_TESTS.md