{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/49305","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/49305/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/49305/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/49305/events","html_url":"https://github.com/rust-lang/rust/pull/49305","id":308033416,"node_id":"MDExOlB1bGxSZXF1ZXN0MTc3MDcyODQ3","number":49305,"title":"Stabilize TryFrom / TryInto, and tweak impls for integers","user":{"login":"SimonSapin","id":291359,"node_id":"MDQ6VXNlcjI5MTM1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/291359?v=4","gravatar_id":"","url":"https://api.github.com/users/SimonSapin","html_url":"https://github.com/SimonSapin","followers_url":"https://api.github.com/users/SimonSapin/followers","following_url":"https://api.github.com/users/SimonSapin/following{/other_user}","gists_url":"https://api.github.com/users/SimonSapin/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonSapin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonSapin/subscriptions","organizations_url":"https://api.github.com/users/SimonSapin/orgs","repos_url":"https://api.github.com/users/SimonSapin/repos","events_url":"https://api.github.com/users/SimonSapin/events{/privacy}","received_events_url":"https://api.github.com/users/SimonSapin/received_events","type":"User","site_admin":false},"labels":[{"id":583437191,"node_id":"MDU6TGFiZWw1ODM0MzcxOTE=","url":"https://api.github.com/repos/rust-lang/rust/labels/S-waiting-on-bors","name":"S-waiting-on-bors","color":"d3dddd","default":false},{"id":211668062,"node_id":"MDU6TGFiZWwyMTE2NjgwNjI=","url":"https://api.github.com/repos/rust-lang/rust/labels/T-libs","name":"T-libs","color":"bfd4f2","default":false},{"id":219670472,"node_id":"MDU6TGFiZWwyMTk2NzA0NzI=","url":"https://api.github.com/repos/rust-lang/rust/labels/final-comment-period","name":"final-comment-period","color":"1e76d9","default":false},{"id":223796632,"node_id":"MDU6TGFiZWwyMjM3OTY2MzI=","url":"https://api.github.com/repos/rust-lang/rust/labels/relnotes","name":"relnotes","color":"fad8c7","default":false}],"state":"closed","locked":false,"assignee":{"login":"sfackler","id":1455697,"node_id":"MDQ6VXNlcjE0NTU2OTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1455697?v=4","gravatar_id":"","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false},"assignees":[{"login":"sfackler","id":1455697,"node_id":"MDQ6VXNlcjE0NTU2OTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1455697?v=4","gravatar_id":"","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false}],"milestone":null,"comments":53,"created_at":"2018-03-23T13:41:32Z","updated_at":"2018-08-08T13:07:50Z","closed_at":"2018-03-27T14:31:56Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/49305","html_url":"https://github.com/rust-lang/rust/pull/49305","diff_url":"https://github.com/rust-lang/rust/pull/49305.diff","patch_url":"https://github.com/rust-lang/rust/pull/49305.patch"},"body":"Fixes https://github.com/rust-lang/rust/issues/33417 (tracking issue)\r\n\r\n----\r\n\r\nThis adds:\r\n\r\n* `impl From<u16> for usize`\r\n* `impl From<i16> for isize`\r\n* `impl From<u8> for isize`\r\n\r\n… 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.\r\n\r\nThe 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.\r\n\r\nNote: 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.\r\n\r\nI chose conservatively to make no assumption about the future there. Users making their portability decisions and using something like `.try_into().unwrap()`.\r\n\r\n----\r\n\r\nSince 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:\r\n\r\n* The `convert::TryFrom` trait\r\n* The `convert::TryFrom` trait\r\n* `impl<T> TryFrom<&[T]> for &[T; $N]` (for `$N` up to 32)\r\n* `impl<T> TryFrom<&mut [T]> for &mut [T; $N]` (for `$N` up to 32)\r\n* The `array::TryFromSliceError` struct, with impls of `Debug`, `Copy`, `Clone`, and `Error`\r\n* `impl TryFrom<u32> for char`\r\n* The `char::CharTryFromError` struct, with impls of `Copy`, `Clone`, `Debug`, `PartialEq`, `Eq`, `Display`, and `Error`\r\n* Impls of `TryFrom` for all (?) combinations of primitive integer types where `From` isn’t implemented.\r\n* The `num::TryFromIntError` struct, with impls of `Debug`, `Copy`, `Clone`, `Display`, `From<!>`, and `Error`\r\n\r\nSome minor remaining questions that I hope can be resolved in this PR:\r\n\r\n* Should the impls for error types be unified?\r\n* ~Should `TryFrom` and `TryInto` be in the prelude? `From` and `Into` are.~ (Yes.)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/411398632","html_url":"https://github.com/rust-lang/rust/pull/49305#issuecomment-411398632","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/49305","id":411398632,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTM5ODYzMg==","user":{"login":"SimonSapin","id":291359,"node_id":"MDQ6VXNlcjI5MTM1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/291359?v=4","gravatar_id":"","url":"https://api.github.com/users/SimonSapin","html_url":"https://github.com/SimonSapin","followers_url":"https://api.github.com/users/SimonSapin/followers","following_url":"https://api.github.com/users/SimonSapin/following{/other_user}","gists_url":"https://api.github.com/users/SimonSapin/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonSapin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonSapin/subscriptions","organizations_url":"https://api.github.com/users/SimonSapin/orgs","repos_url":"https://api.github.com/users/SimonSapin/repos","events_url":"https://api.github.com/users/SimonSapin/events{/privacy}","received_events_url":"https://api.github.com/users/SimonSapin/received_events","type":"User","site_admin":false},"created_at":"2018-08-08T13:07:50Z","updated_at":"2018-08-08T13:07:50Z","author_association":"CONTRIBUTOR","body":"It looks like `time_t` is always either `i32` or `i64`. So converting to `u64` is fallible in both cases because of negative values. Converting from `u64` is also fallible in both cases because of very large values. So you’d always get `TryFrom` impls with `type Error = TryFromIntError;`.\r\n\r\nNote that infallible conversions still get a `TryFrom` impl through `impl<T, U> TryFrom<U> for T where T: From<U> { type Error = !; }`. So if you were to convert `time_t` to/from `i64` instead of `u64` for example, then the `try_*` methods would be available on all platforms but with a varying error type. However it’s still possible to write portable code without using `#[cfg]`. For example:\r\n\r\n```rust\r\nfn foo(x: u64) -> Result<time_t, TryFromIntError> {\r\n    Ok(x.try_into()?)\r\n}\r\n```\r\n\r\nThis works because `?` does error type conversion. Depending on the platform this ends up calling `impl From<!> for TryFromIntError` or the no-op `impl<T> From<T> for T`."}}
{"actor":{"display_login":"SimonSapin"}}