-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Ipv6Addr <-> u128 #39324
Ipv6Addr <-> u128 #39324
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Sounds reasonable to me! |
I think to fix the errors on Travis we'll want to tag these with @rfcbot fcp merge |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, 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. |
Aren't 128-bit ints cfg'd in some target-specific way? These are defined unconditionally. |
@brson are there any tier 1 platforms where this happens? Because if that's the case, bors will catch that EDIT: I tried |
1e954f3
to
c978631
Compare
@brson that's a good point, actually. I'm not sure what we should consider the status of u128/i128 in terms of portability. I believe that all current platforms Rust targets supports the types but that doesn't necessarily mean that all future platforms will. |
@alexcrichton I personally think that a catch-all |
I'm not sure I understand the portability issues with u/i128. How are those different than e.g. u/i64? |
c978631
to
5a94c5b
Compare
src/libstd/net/ip.rs
Outdated
@@ -1153,6 +1153,28 @@ impl FromInner<c::in6_addr> for Ipv6Addr { | |||
} | |||
} | |||
|
|||
#[cfg(not(stage0))] | |||
#[stable(feature = "ipv6_u128", since = "1.17.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are still unstable so should be #[unstable(feature = "i128", issue="35118")]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impls can't be unstable so I made it stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct but rustdoc will display the version number on impls that are marked stable and 1.17.0 is clearly wrong for these.
src/libstd/net/ip.rs
Outdated
impl From<Ipv6Addr> for u128 { | ||
fn from(ip: Ipv6Addr) -> u128 { | ||
let ip = ip.segments(); | ||
((ip[0] as u128) << 104) + ((ip[1] as u128) << 96) + ((ip[2] as u128) << 80) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
104
-> 112
.
Personally I would use u128::from()
for these rather than as u128
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly copy-pasted the one from IPv4; is the difference worthwhile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, either way works fine.
src/libstd/net/ip.rs
Outdated
impl From<u128> for Ipv6Addr { | ||
fn from(ip: u128) -> Ipv6Addr { | ||
Ipv6Addr::new( | ||
(ip >> 104) as u16, (ip >> 96) as u16, (ip >> 80) as u16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
104
->112
.
src/libstd/net/ip.rs
Outdated
@@ -1515,6 +1537,18 @@ mod tests { | |||
} | |||
|
|||
#[test] | |||
fn test_ipv6_to_int() { | |||
let a = Ipv4Addr::new(0xffff, 0xffff, 0xffff, 0xffff, 127, 0, 0, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ipv4Addr
-> Ipv6Addr
for here and the two below.
src/libstd/net/ip.rs
Outdated
@@ -1515,6 +1537,18 @@ mod tests { | |||
} | |||
|
|||
#[test] | |||
fn test_ipv6_to_int() { | |||
let a = Ipv4Addr::new(0xffff, 0xffff, 0xffff, 0xffff, 127, 0, 0, 1); | |||
assert_eq!(u128::from(a), 0xffffffffffffffff0080000000000001u128); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0xffffffffffffffff0080000000000001u128
-> 0xffffffffffffffff007f000000000001u128
for here and below.
Although it might be better to use examples like the ipv6_from_segments
test where getting a shift wrong (like using 104 instead of 112) will definitely cause these tests to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you there. I'll update the IPv4 test too.
The latest travis errors seem to be an error in parsing the integer literals. |
Most likely a staging issue of some sort; these literals work just fine on a proper nightly compiler. |
Further comments here. |
ping @brson @BurntSushi (checkboxes) |
Also @clarcharr it looks like there's still failing tests on travis? |
The test should get fixed automatically when we release the new beta, so I do not see any point in trying to fix it now only to undo it a few days later. |
Yeah, I'm not particularly sure how to fix it myself. It seems to be accepting u128 as a type but not the integer literal, which indicates that it's probably not a staging issue. |
9fd1fba
to
4659884
Compare
This was discussed at the libs triage a little while ago, and the conclusion was that we'll merge this for now but consider the portability of i128/u128 in the tracking issue (and before stabilizing). @clarcharr want to rebase and remove the stage0 annotations? With a new stage0 I think they may not be necessary any more. |
c186a4f
to
3ef7428
Compare
3ef7428
to
8b2e334
Compare
@alexcrichton I removed the stage0 cfgs and Travis is passing now. |
Thanks! ping @brson (checkbox) |
@bors: r+ |
📌 Commit 8b2e334 has been approved by |
⌛ Testing commit 8b2e334 with merge 1807904... |
💔 Test failed - status-travis |
… On Tue, Feb 7, 2017 at 2:12 PM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/rust/builds/199377916>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39324 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95FiodMpcLi8XL5TIQB4olH2iXSpHks5raOw4gaJpZM4LvJRu>
.
|
Ipv6Addr <-> u128 Because we have `u128` now, it makes sense to add a conversion between `Ipv6Addr` and `u128` in addition to the existing one between `Ipv4Addr` and `u32`. This shouldn't violate the existing feature gate on `u128` because you can't use the type without the feature gate, but if i have to add something, I can.
💔 Test failed - status-travis |
… On Tue, Feb 7, 2017 at 3:56 PM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/rust/builds/199403284>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39324 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95Nqayxvk1y82HmWmN9IIxQY8Q428ks5raQSWgaJpZM4LvJRu>
.
|
Ipv6Addr <-> u128 Because we have `u128` now, it makes sense to add a conversion between `Ipv6Addr` and `u128` in addition to the existing one between `Ipv4Addr` and `u32`. This shouldn't violate the existing feature gate on `u128` because you can't use the type without the feature gate, but if i have to add something, I can.
☀️ Test successful - status-appveyor, status-travis |
Because we have
u128
now, it makes sense to add a conversion betweenIpv6Addr
andu128
in addition to the existing one betweenIpv4Addr
andu32
.This shouldn't violate the existing feature gate on
u128
because you can't use the type without the feature gate, but if i have to add something, I can.