{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/29220","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/29220/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/29220/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/29220/events","html_url":"https://github.com/rust-lang/rust/pull/29220","id":112702341,"number":29220,"title":"Add additional automatic conversions to usize/isize.","user":{"login":"briansmith","id":16816,"avatar_url":"https://avatars.githubusercontent.com/u/16816?v=3","gravatar_id":"","url":"https://api.github.com/users/briansmith","html_url":"https://github.com/briansmith","followers_url":"https://api.github.com/users/briansmith/followers","following_url":"https://api.github.com/users/briansmith/following{/other_user}","gists_url":"https://api.github.com/users/briansmith/gists{/gist_id}","starred_url":"https://api.github.com/users/briansmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briansmith/subscriptions","organizations_url":"https://api.github.com/users/briansmith/orgs","repos_url":"https://api.github.com/users/briansmith/repos","events_url":"https://api.github.com/users/briansmith/events{/privacy}","received_events_url":"https://api.github.com/users/briansmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-10-21T23:56:32Z","updated_at":"2015-10-22T21:20:41Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/29220","html_url":"https://github.com/rust-lang/rust/pull/29220","diff_url":"https://github.com/rust-lang/rust/pull/29220.diff","patch_url":"https://github.com/rust-lang/rust/pull/29220.patch"},"body":"Also, improve the documentation related to the range of usize and isize.\r\n\r\nSee https://github.com/rust-lang/rfcs/pull/1218#issuecomment-146615171 and https://github.com/rust-lang/rust/pull/28921#issuecomment-149427316.\r\n\r\nI decided to be conservative and assume that 16-bit platform support might be added in the future, because C99 supports platforms with 16-bit `size_t`. In particular, C99 specifies that the range of `size_t` is at least [0, 65535]; i.e. `SIZE_MAX` must be at least `65,535` and so `sizeof(size_t) >= 2`."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/150359480","html_url":"https://github.com/rust-lang/rust/pull/29220#issuecomment-150359480","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/29220","id":150359480,"user":{"login":"briansmith","id":16816,"avatar_url":"https://avatars.githubusercontent.com/u/16816?v=3","gravatar_id":"","url":"https://api.github.com/users/briansmith","html_url":"https://github.com/briansmith","followers_url":"https://api.github.com/users/briansmith/followers","following_url":"https://api.github.com/users/briansmith/following{/other_user}","gists_url":"https://api.github.com/users/briansmith/gists{/gist_id}","starred_url":"https://api.github.com/users/briansmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briansmith/subscriptions","organizations_url":"https://api.github.com/users/briansmith/orgs","repos_url":"https://api.github.com/users/briansmith/repos","events_url":"https://api.github.com/users/briansmith/events{/privacy}","received_events_url":"https://api.github.com/users/briansmith/received_events","type":"User","site_admin":false},"created_at":"2015-10-22T21:20:41Z","updated_at":"2015-10-22T21:20:41Z","body":"> When discussing #28921 the libs team decided to punt on isize/usize for now until a compelling use case came up, so I'm curious but do you have a use case in mind for these conversions?\r\n\r\nI mostly deal with networking protocols, and networking protocols frequently specify that certain quantities are 8 or 16 bits wide. For example., [the TLS 1.2 spec](https://tools.ietf.org/html/rfc5246) has several quantities defined as `uint16`. Several related protocols do likewise. I generally store such quantities as u16 in my code in order to document their range. (I would actually prefer a `uint_fast16_t` sometimes.) Like @petrochenkov, I am working on improving the type-safety of my code by eliminating uses of the Rust `as` operator, because `as` is too error-prone for safety-critical code. This is part of that effort.\r\n\r\n> Also guaranteeing that isize or usize is at least 16 bits is a language change that would need to go through an RFC most likely rather than just a PR here.\r\n\r\nI will post an RFC.\r\n\r\n> Conversions u32 -> usize are the most useful, but they are not included in this PR and should be guarded by cfg if we are going to encourage the AVR port.\r\n\r\nLike I mentioned, I purposely didn't include those because they are not AVR-compatible. Regardless, you are right that there is a need for a `widen` like you defined that works for `u32` and `i32`, for code that will never execute on a 16-bit platform. That includes lots of operating-system-specific code for IOS, Windows, and other platforms that don't support 16-bit systems. But, I think it would be best to do that separately, because I think it is not clear how to best support that. In particular, I definitely think it would be neat to design things in a way that encourages 16-bit-microcontroller-friendly code, but realistically a lot of developers just don't have the time or interest to deal with that."}}