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 upStabilize TryFrom / TryInto, and tweak impls for integers #49305
Conversation
rust-highfive
assigned
Mark-Simulacrum
Mar 23, 2018
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 @Mark-Simulacrum (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. Due to 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. |
rust-highfive
added
the
S-waiting-on-review
label
Mar 23, 2018
rust-highfive
assigned
sfackler
and unassigned
Mark-Simulacrum
Mar 23, 2018
SimonSapin
added
T-libs
relnotes
labels
Mar 23, 2018
SimonSapin
force-pushed the
SimonSapin:fallible
branch
from
a3e631e
to
8331925
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
I think they should, so I added a commit that makes them so. Let’s see if anyone objects :) |
This comment has been minimized.
This comment has been minimized.
|
We already did the FCP dance in the tracking issue, but just to get eyes on this again: @rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 26, 2018
•
|
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
the
proposed-final-comment-period
label
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
The problem with this is that when (and I hope it's a when) the missing |
This comment has been minimized.
This comment has been minimized.
|
@ollie27 Which impls are you saying are missing? After this PR I believe that that every impl that can be implemented in on all platforms between primitive integers are already implemented. There shouldn’t be any we haven’t gotten around to yet. As to type aliases like |
This comment has been minimized.
This comment has been minimized.
All of the impls that aren't strictly speaking portable. They were proposed in #37423 but postponed for the portability lint.
Exactly. I don't see why people can't do this for |
This comment has been minimized.
This comment has been minimized.
|
As far as I can tell the portability lint wouldn’t help much here. We want
Just because a work around exists doesn’t mean it’s not bad. This PR tries to avoid this situation where we can. |
This comment has been minimized.
This comment has been minimized.
|
Just to be clear, are you saying that the impls proposed in #37423 will never be added? If you are then I strongly oppose that. Having |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 26, 2018
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
With this PR as originally proposed, indeed those could never be added as they would conflict with impls being stabilized here. When discussing this offline @sfackler suggested that with the portability lint we could have some The set of impls that would be affected is not obvious so I tried to make an exhaustive table (with the same assumptions about pointer width than in this PR’s original message: at least 16 bits, but no assumed upper bound)
Legend:
Whatever else we do, the few I think there are four things we can do with the rest:
I’m now leaning toward 3 or 4. |
This comment has been minimized.
This comment has been minimized.
|
I think 4 may be the cleanest but 3 also seems fine. |
SimonSapin
added a commit
to SimonSapin/rust
that referenced
this pull request
Mar 26, 2018
SimonSapin
force-pushed the
SimonSapin:fallible
branch
from
9942101
to
f3d46e7
Mar 26, 2018
SimonSapin
added a commit
to SimonSapin/rust
that referenced
this pull request
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
I’ve implemented 3 since that seems more useful. Most users don’t need to figure out mentally which impls exist or not, they can just try to use it and see what happens. I’ve had to modify range iterators and r? @sfackler |
This comment has been minimized.
This comment has been minimized.
|
|
SimonSapin
force-pushed the
SimonSapin:fallible
branch
from
f3d46e7
to
adf53de
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
The policy you refer includes:
There was some discussion in hyperium/http#192. I will repeat my main point here: The Rust team has advertised stability as a feature in such a way that it implied to me that pinning the stable rust version was not needed. To downstream users, it doesn't actually matter if a change is “minor” or not, it matters if the build will break. If the Rust team is not reasonably able to provide a guarantee of stability, that is fine but should be advertised and downstream users can adjust best practices by, for example, pinning the stable version of Rust. Again if this change lands on Rust stable, it will break the existing frozen Conduit builds due to the fact that we did not pin the version of Rust but dependencies are pinned. We cannot fix these past version releases as they have been cut. |
This comment has been minimized.
This comment has been minimized.
|
To be explicit, I understand that almost literally any change to If this interpretation is not correct, I would appreciate it if the Rust team goes on the record to clarify the policy, because at least I and probably others are under the assumption that we can expect stability across Rust releases. If this assumption is not correct, we need to change our practices to start pinning the compiler version in applications. |
This comment has been minimized.
This comment has been minimized.
|
With the new 2018 edition coming soon, it seems reasonable to include these in the prelude only in the newer editions. It prevents any breakage. |
This comment has been minimized.
This comment has been minimized.
|
@carllerche Completely agree. We have roughly 6 weeks before this change reaches the stable channel. 1.26 goes to beta this week (today?) and the plan was to wait for crater results for that beta to get an idea of how bad the breakage is in the ecosystem. I’ll talk with other libs team member today to see what they think of reverting the prelude addition sooner than that based on the reports on @seanmonstar Indeed we’ve discussed having a larger prelude based on a crate’s edition. That could be an opportunity to add |
konstin
referenced this pull request
Mar 29, 2018
Closed
Build broken by TryFrom on latest nightly #136
This was referenced Mar 29, 2018
rleungx
referenced this pull request
Mar 30, 2018
Closed
Cargo build failed with rustc 1.26.0-nightly #12
This comment has been minimized.
This comment has been minimized.
tirkarthi
commented
Mar 30, 2018
•
|
To add to this Build : https://travis-ci.org/rust-lang-nursery/rand/jobs/359738013 |
This was referenced Mar 30, 2018
This comment has been minimized.
This comment has been minimized.
tirkarthi
commented
Mar 30, 2018
|
I downloaded the modules metadata from https://github.com/rust-lang/crates.io-index and inserted them into MongoDB to analyze the number of modules that might break. I did a query for stdweb and http. I also did a query on the number of packages that depend on rand which uses stdweb. The approx results are as below : stdweb - 15 dependants Gist of dependencies : https://gist.github.com/tirkarthi/846f9d2fd87c90463c5ca9cf99f3d44d |
SimonSapin
referenced this pull request
Mar 30, 2018
Merged
Revert "Add TryFrom and TryInto to the prelude" #49518
This comment has been minimized.
This comment has been minimized.
|
FYI, @SimonSapin opened a PR which reverts the |
bors
added a commit
that referenced
this pull request
Mar 30, 2018
This comment has been minimized.
This comment has been minimized.
|
Oops, I meant to comment about this here but forgot. Thanks @frewsxcv. As mentioned in that PR I’d still like to figure something out later, but for now let’s fix immediate breakage. |
This was referenced Apr 2, 2018
cr1901
referenced this pull request
Apr 3, 2018
Closed
"error: unused macro definition" when trying to compile libcore for msp430 target with recent nightly. #49617
ltratt
added a commit
to softdevteam/lrpar
that referenced
this pull request
Apr 3, 2018
boomshroom
referenced this pull request
Apr 4, 2018
Closed
Usize conversions removed from nightly #11
npmccallum
referenced this pull request
Apr 21, 2018
Open
Invalid collision with TryFrom implementation? #50133
SimonSapin
referenced this pull request
Jun 7, 2018
Closed
Tracking issue for the 2018 edition’s prelude #51418
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
SoniEx2
commented
Aug 8, 2018
|
How does one handle something like libc::time_t using the new TryFrom? |
This comment has been minimized.
This comment has been minimized.
|
@SoniEx2 A merged or otherwise closed PR/issue is often not a good place to ask question. Consider asking on #33417 or on https://internals.rust-lang.org/ instead. But also: what do you mean by "handle"? Convert to/from what other type? |
This comment has been minimized.
This comment has been minimized.
SoniEx2
commented
Aug 8, 2018
|
say I need to turn a time_t to/from u64. since time_t can change types, this seems like I'd have to be putting either "as" or #[cfg] everywhere? none of them let me write code that "just works"... I wonder why we couldn't have multiple otherwise identical TryFroms with different error types... |
This comment has been minimized.
This comment has been minimized.
|
It looks like Note that infallible conversions still get a fn foo(x: u64) -> Result<time_t, TryFromIntError> {
Ok(x.try_into()?)
}This works because |
SimonSapin commentedMar 23, 2018
•
edited
Fixes #33417 (tracking issue)
This adds:
impl From<u16> for usizeimpl From<i16> for isizeimpl From<u8> for isize… replacing corresponding
TryFrom<Error=!>impls. (TryFromstill applies through the genericimpl<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
TryFromimpls that definetype Error = !all involveusizeorisize. This PR changes them to useTryFromIntErrorinstead, 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
Fromimpls converting pointer-sized integers to large fixed-size integers. RISC-V considers the possibility of a 128-bit address space (RV128), which would leave onlyimpl From<usize> for u128andimpl From<isize> for u128. I found some things about 256-bit “capabilities”, but I don’t know how relevant that would be to Rust’susizeandisizetypes.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 #33417, this PR also proposes stabilize the following items:
convert::TryFromtraitconvert::TryFromtraitimpl<T> TryFrom<&[T]> for &[T; $N](for$Nup to 32)impl<T> TryFrom<&mut [T]> for &mut [T; $N](for$Nup to 32)array::TryFromSliceErrorstruct, with impls ofDebug,Copy,Clone, andErrorimpl TryFrom<u32> for charchar::CharTryFromErrorstruct, with impls ofCopy,Clone,Debug,PartialEq,Eq,Display, andErrorTryFromfor all (?) combinations of primitive integer types whereFromisn’t implemented.num::TryFromIntErrorstruct, with impls ofDebug,Copy,Clone,Display,From<!>, andErrorSome minor remaining questions that I hope can be resolved in this PR:
Should(Yes.)TryFromandTryIntobe in the prelude?FromandIntoare.