-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement always-fallible TryFrom for usize/isize conversions that are infallible on some platforms #51564
Conversation
…le with a portability lint" This reverts commit 837d6c7. Fixes rust-lang#49415
(rust_highfive has picked a reviewer for you, use r? to override) |
@rfcbot fcp merge |
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. |
So if a trait impl can't be implemented for all targets it shouldn't be implemented for any even with a portability lint? Is that going to be the new policy or is there something special about The way I see it is that having different error types for impls like fn main() {
assert_eq!(4294967296usize, 1usize << 32);
}
|
This presumes the existence of a portability lint, which most likely won’t be the case for many months yet. By the way this is why non-pointer-sized |
Thanks for this @SimonSapin -- I know quite a few of us will be grateful for this one being merged! |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
While I agree with @ollie27 that Performance-wise it also shouldn't make much of a difference, since presumably the optimizer will be able to figure out that a |
Indeed, those conversions are marked |
@bors: r+ |
📌 Commit e7c122c has been approved by |
This issue was never about performance. I don't know why people keep mentioning that. This issue is about whether the The question now is, if those impls won't be allowed, will the portability lint be usable for any trait impls? |
Right, this isn’t about performance, I was only responding that it isn’t a concern.
Right, and this PR is proposing that they can not because we’re adding different, overlapping impls.
This proposal is almost the same as adding Which I think we should’t do without a portability lint. And even then, as mentioned in this PR’s description marking some
That is a question that is unresolved as far as I know: will the lint be powerful enough to detect portability issues in enough cases. (For example: using a blanket portable impl which depends on a non-portable impl.) |
Implement always-fallible TryFrom for usize/isize conversions that are infallible on some platforms This reverts commit 837d6c7 "Remove TryFrom impls that might become conditionally-infallible with a portability lint". This fixes rust-lang#49415 by adding (restoring) missing `TryFrom` impls for integer conversions to or from `usize` or `isize`, by making them always fallible at the type system level (that is, with `Error=TryFromIntError`) even though they happen to be infallible on some platforms (for some values of `size_of::<usize>()`). They had been removed to allow the possibility to conditionally having some of them be infallible `From` impls instead, depending on the platforms, and have the [portability lint](rust-lang/rfcs#1868) warn when they are used in code that is not already opting into non-portability. For example `#[allow(some_lint)] usize::from(x: u64)` would be valid on code that only targets 64-bit platforms. This PR gives up on this possiblity for two reasons: * Based on discussion with @aturon, it seems that the portability lint is not happening any time soon. It’s better to have the conversions be available *at all* than keep blocking them for so long. Portability-lint-gated platform-specific APIs can always be added separately later. * For code that is fine with fallibility, the alternative would force it to opt into "non-portability" even though there would be no real portability issue.
Implement always-fallible TryFrom for usize/isize conversions that are infallible on some platforms This reverts commit 837d6c7 "Remove TryFrom impls that might become conditionally-infallible with a portability lint". This fixes #49415 by adding (restoring) missing `TryFrom` impls for integer conversions to or from `usize` or `isize`, by making them always fallible at the type system level (that is, with `Error=TryFromIntError`) even though they happen to be infallible on some platforms (for some values of `size_of::<usize>()`). They had been removed to allow the possibility to conditionally having some of them be infallible `From` impls instead, depending on the platforms, and have the [portability lint](rust-lang/rfcs#1868) warn when they are used in code that is not already opting into non-portability. For example `#[allow(some_lint)] usize::from(x: u64)` would be valid on code that only targets 64-bit platforms. This PR gives up on this possiblity for two reasons: * Based on discussion with @aturon, it seems that the portability lint is not happening any time soon. It’s better to have the conversions be available *at all* than keep blocking them for so long. Portability-lint-gated platform-specific APIs can always be added separately later. * For code that is fine with fallibility, the alternative would force it to opt into "non-portability" even though there would be no real portability issue.
☀️ Test successful - status-appveyor, status-travis |
This reverts commit 837d6c7 "Remove TryFrom impls that might become conditionally-infallible with a portability lint".
This fixes #49415 by adding (restoring) missing
TryFrom
impls for integer conversions to or fromusize
orisize
, by making them always fallible at the type system level (that is, withError=TryFromIntError
) even though they happen to be infallible on some platforms (for some values ofsize_of::<usize>()
).They had been removed to allow the possibility to conditionally having some of them be infallible
From
impls instead, depending on the platforms, and have the portability lint warn when they are used in code that is not already opting into non-portability. For example#[allow(some_lint)] usize::from(x: u64)
would be valid on code that only targets 64-bit platforms.This PR gives up on this possiblity for two reasons:
Based on discussion with @aturon, it seems that the portability lint is not happening any time soon. It’s better to have the conversions be available at all than keep blocking them for so long. Portability-lint-gated platform-specific APIs can always be added separately later.
For code that is fine with fallibility, the alternative would force it to opt into "non-portability" even though there would be no real portability issue.