Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd additional automatic conversions to usize/isize. #29220
Conversation
rust-highfive
assigned
aturon
Oct 21, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
briansmith
referenced this pull request
Oct 22, 2015
Closed
Improve safety & usability of |size_t| and |ssize_t|. #29222
This comment has been minimized.
This comment has been minimized.
|
See https://internals.rust-lang.org/t/adding-16-bit-pointer-support/2484 where somebody is trying to add support for a 16-bit platform that (IMO) Rust should support. This is why I didn't add conversions from |
briansmith
referenced this pull request
Oct 22, 2015
Merged
Implement conversion traits for primitive integer types #28921
This comment has been minimized.
This comment has been minimized.
|
When discussing #28921 the libs team decided to punt on Also guaranteeing that |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton |
This comment has been minimized.
This comment has been minimized.
I 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 has several quantities defined as
I will post an RFC.
Like 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 |
This comment has been minimized.
This comment has been minimized.
|
I would like an |
This comment has been minimized.
This comment has been minimized.
Portability to 16-bit is a pretty niche concern, unlike portability between 32-bit and 64-bit. In my proposed lint-based solution (#28921 (comment), #28921 (comment)) we can have a lint for 16-bit portability too, but disabled by default. |
This comment has been minimized.
This comment has been minimized.
|
Even in |
briansmith
referenced this pull request
Oct 23, 2015
Open
Remove all casts that use the `as` operator #31
petrochenkov
reviewed
Oct 23, 2015
| @@ -413,6 +415,8 @@ mod prim_isize { } | |||
| // | |||
| /// The pointer-sized unsigned integer type. | |||
| /// | |||
| /// `usize` is guaranteed to be at least as large as `u16`. | |||
This comment has been minimized.
This comment has been minimized.
petrochenkov
Oct 23, 2015
Contributor
I don't think this change to the language (and therefore RFC) is required. If we ever support a platform with 8-bit pointers (which is unlikely, but still) it would be much easier to just insert a cfg before impl_from! { u16, usize }.
For reference:
For the smallest AVR devices with less than 256 bytes of SRAM the tiny memory model
can be used in many cases. When using tiny memory model, all variables in SRAM are
accessed with 8-bit pointers instead of 16-bit pointers. This reduces the code size for
loading pointer values.
This comment has been minimized.
This comment has been minimized.
briansmith
Oct 24, 2015
Author
don't think this change to the language (and therefore RFC) is required. If we ever support a platform with 8-bit pointers (which is unlikely, but still) it would be much easier to just insert a cfg before impl_from! { u16, usize }.
Even if we wanted to support the tiny memory model, usize would still have to be at least 16 bits, because size_t would still be 16 bits, and usize being smaller than size_t would mean that usize is smaller than size_t, which would make dealing with the FFI in a generic way very complicated.
This comment has been minimized.
This comment has been minimized.
|
I also personally want u32/i32 -> usize/isize conversions, but that still doesn't mean it can be changed here without an RFC. Thanks for the use cases though, they sound like good candidates for motivation in the RFC! |
This comment has been minimized.
This comment has been minimized.
|
The "automatic" in the title is confusing, since this isn't some sort of a coercion, just a set of library trait impls. |
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov
referenced this pull request
Dec 20, 2015
Closed
the trait `core::convert::From<usize>` is not implemented for the type `u64` #30495
This comment has been minimized.
This comment has been minimized.
|
What's the status of this PR? |
This comment has been minimized.
This comment has been minimized.
|
Closing due to inactivity, but I think that we'll likely want to decide about usize/isize separately before taking further action on this PR. |
briansmith commentedOct 21, 2015
Also, improve the documentation related to the range of usize and isize.
See rust-lang/rfcs#1218 (comment) and #28921 (comment).
I 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 ofsize_tis at least [0, 65535]; i.e.SIZE_MAXmust be at least65,535and sosizeof(size_t) >= 2.