Skip to content
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 PartialOrd and Ord for SocketAddr* #72239

Merged
merged 3 commits into from
May 29, 2020
Merged

Conversation

hch12907
Copy link
Contributor

The implementation is mostly the same as the one found in IpAddr (other than adding comparison for ports, of course).
Continues #53788 and #53863
Fixes #53710

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @LukasKalbertodt (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 rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 15, 2020
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 43'
Agent machine name: 'fv-az578'
Current agent version: '2.168.2'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200430.2
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200430.2/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.2)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/610cc602-0c37-4337-96aa-5f643b8dcd64.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/72239/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/72239/merge:refs/remotes/pull/72239/merge
---
 ---> 3adb0605cc65
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 28dbc326cb7f
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 537a01811900
Successfully built 537a01811900
Successfully tagged rust-ci:latest
Built container sha256:537a018119009dc218456238dec90b5530050db1e2a1e166550c218003f6159d
---
    Checking panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
error[E0053]: method `eq` has an incompatible type for trait
   --> src/libstd/net/addr.rs:677:5
    |
677 |     fn eq(&self, other: &SocketAddrV4) -> bool {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `net::addr::SocketAddr`, found struct `net::addr::SocketAddrV4`
    |
    = note: expected fn pointer `fn(&net::addr::SocketAddrV4, &net::addr::SocketAddr) -> _`
               found fn pointer `fn(&net::addr::SocketAddrV4, &net::addr::SocketAddrV4) -> _`
error[E0053]: method `eq` has an incompatible type for trait
   --> src/libstd/net/addr.rs:686:5
    |
    |
686 |     fn eq(&self, other: &SocketAddrV6) -> bool {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `net::addr::SocketAddr`, found struct `net::addr::SocketAddrV6`
    |
    = note: expected fn pointer `fn(&net::addr::SocketAddrV6, &net::addr::SocketAddr) -> _`
               found fn pointer `fn(&net::addr::SocketAddrV6, &net::addr::SocketAddrV6) -> _`
error[E0308]: mismatched types
   --> src/libstd/net/addr.rs:679:13
    |
678 |         match other {
678 |         match other {
    |               ----- this expression has type `&net::addr::SocketAddrV4`
679 |             SocketAddr::V4(v4) => self == v4,
    |             ^^^^^^^^^^^^^^^^^^ expected struct `net::addr::SocketAddrV4`, found enum `net::addr::SocketAddr`
error[E0308]: mismatched types
   --> src/libstd/net/addr.rs:680:13
    |
678 |         match other {
678 |         match other {
    |               ----- this expression has type `&net::addr::SocketAddrV4`
679 |             SocketAddr::V4(v4) => self == v4,
680 |             SocketAddr::V6(_) => false,
    |             ^^^^^^^^^^^^^^^^^ expected struct `net::addr::SocketAddrV4`, found enum `net::addr::SocketAddr`
error[E0308]: mismatched types
   --> src/libstd/net/addr.rs:688:13
    |
687 |         match other {
687 |         match other {
    |               ----- this expression has type `&net::addr::SocketAddrV6`
688 |             SocketAddr::V4(_) => false,
    |             ^^^^^^^^^^^^^^^^^ expected struct `net::addr::SocketAddrV6`, found enum `net::addr::SocketAddr`
error[E0308]: mismatched types
   --> src/libstd/net/addr.rs:689:13
    |
687 |         match other {
687 |         match other {
    |               ----- this expression has type `&net::addr::SocketAddrV6`
688 |             SocketAddr::V4(_) => false,
689 |             SocketAddr::V6(v6) => self == v6,
    |             ^^^^^^^^^^^^^^^^^^ expected struct `net::addr::SocketAddrV6`, found enum `net::addr::SocketAddr`
error: aborting due to 6 previous errors

Some errors have detailed explanations: E0053, E0308.
For more information about an error, try `rustc --explain E0053`.
---
  local time: Fri May 15 19:04:22 UTC 2020
  network time: Fri, 15 May 2020 19:04:22 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/72239/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/72239/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (3383) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-8 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux x86_64-gnu-llvm-8
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 43'
Agent machine name: 'fv-az578'
Current agent version: '2.168.2'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200430.2
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200430.2/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.2)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/e00602f2-48e4-4420-ae60-ebc7c2bc4876.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/72239/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/72239/merge:refs/remotes/pull/72239/merge
---
 ---> cb2676f08729
Step 5/8 : ENV RUST_CONFIGURE_ARGS       --build=x86_64-unknown-linux-gnu       --llvm-root=/usr/lib/llvm-8       --enable-llvm-link-shared       --set rust.thin-lto-import-instr-limit=10
 ---> Using cache
 ---> df25ce111862
Step 6/8 : ENV SCRIPT python2.7 ../x.py test --exclude src/tools/tidy &&            python2.7 ../x.py test src/test/mir-opt --pass=build                                   --target=armv5te-unknown-linux-gnueabi &&            python2.7 ../x.py test src/tools/tidy
 ---> 599b9ac96b27
Step 7/8 : ENV NO_DEBUG_ASSERTIONS=1
 ---> Using cache
 ---> 091087e35a36
---
   Compiling fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
   Compiling chalk-rust-ir v0.10.0
   Compiling rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
   Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
   Compiling rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
   Compiling chalk-solve v0.10.0
   Compiling rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
   Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
   Compiling rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
   Compiling fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
   Compiling chalk-rust-ir v0.10.0
   Compiling rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
   Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
   Compiling rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
   Compiling chalk-solve v0.10.0
   Compiling rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
   Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
   Compiling rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
......................................................i............................................. 1800/10167
.................................................................................................... 1900/10167
........................................................................i..i........................ 2000/10167
.................................................................................................... 2100/10167
...............................................................iiiii................................ 2200/10167
.................................................................................................... 2400/10167
.................................................................................................... 2500/10167
.................................................................................................... 2600/10167
.................................................................................................... 2700/10167
---
.................................................................................................... 5200/10167
.................................................................................................... 5300/10167
.........................i.......................................................................... 5400/10167
..................i................................................................................. 5500/10167
..........................ii.ii........i...i........................................................ 5600/10167
............................................................................i....................... 5800/10167
.................................................................................................... 5900/10167
.......................ii.....................................i..................................... 6000/10167
.................................................................................................... 6100/10167
.................................................................................................... 6100/10167
.................................................................................................... 6200/10167
....................................................................................ii...i..ii...... 6300/10167
.................................................................................................... 6500/10167
.................................................................................................... 6600/10167
.................................................................................................... 6700/10167
.................................................................................................... 6700/10167
.................i..ii.............................................................................. 6800/10167
.................................................................................................... 7000/10167
.......................................................................i............................ 7100/10167
.................................................................................................... 7200/10167
.................................................................................................... 7300/10167
---
.................................................................................................... 8100/10167
.................................................................................................... 8200/10167
.........................................................................................i.......... 8300/10167
.................................................................................................... 8400/10167
...........................................iiiiii.iiiii.i........................................... 8500/10167
.................................................................................................... 8700/10167
.................................................................................................... 8800/10167
.................................................................................................... 8900/10167
.................................................................................................... 9000/10167
---
Suite("src/test/codegen") not skipped for "bootstrap::test::Codegen" -- not in ["src/tools/tidy"]
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 188 tests
iiii......i.............ii.i..........i...............................i..i..................i....i.. 100/188
..........i.i.i...iii..iiiiiiiiiiiiiiii.......................iii...............ii......

 finished in 5.965
Suite("src/test/codegen-units") not skipped for "bootstrap::test::CodegenUnits" -- not in ["src/tools/tidy"]
Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
Suite("src/test/assembly") not skipped for "bootstrap::test::Assembly" -- not in ["src/tools/tidy"]
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 9 tests
iiiiiiiii

 finished in 0.179
Suite("src/test/incremental") not skipped for "bootstrap::test::Incremental" -- not in ["src/tools/tidy"]
Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
Suite("src/test/debuginfo") not skipped for "bootstrap::test::Debuginfo" -- not in ["src/tools/tidy"]
Check compiletest suite=debuginfo mode=debuginfo (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 115 tests
iiiii..i.....i..i...i..i.i.i..i..i..ii....i.i....ii..........iiii.........i.....i..i.......ii.i.ii.. 100/115
...iiii.....ii.

 finished in 16.271
Suite("src/test/ui-fulldeps") not skipped for "bootstrap::test::UiFullDeps" -- not in ["src/tools/tidy"]
Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---

   Doc-tests core

running 2557 tests
......iiiii......................................................................................... 100/2557
.......................................................................................ii........... 200/2557
.........................i.......................................................................... 400/2557
...............................................................................i..i................. 500/2557
.iiii............................................................................................... 600/2557
.................................................................................................... 700/2557
---
 finished in 3.698
Set({"src/libstd"}) not skipped for "bootstrap::test::Crate" -- not in ["src/tools/tidy"]
Testing std stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling std v0.0.0 (/checkout/src/libstd)
error[E0277]: can't compare `net::addr::SocketAddrV4` with `net::addr::SocketAddrV6`
     |
     |
1227 |         assert!(v4_1 != v6_1);
     |                      ^^ no implementation for `net::addr::SocketAddrV4 == net::addr::SocketAddrV6`
     |
     = help: the trait `core::cmp::PartialEq<net::addr::SocketAddrV6>` is not implemented for `net::addr::SocketAddrV4`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `std`.
---
  local time: Fri May 15 20:42:05 UTC 2020
  network time: Fri, 15 May 2020 20:42:05 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/72239/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/72239/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (3504) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@retep998
Copy link
Member

Aren't trait impls insta-stable?

@hch12907
Copy link
Contributor Author

hch12907 commented May 16, 2020

To be honest, I wasn't really sure.. which is why I played it safe by making them unstable. Should I just change all the instances of #[unstable(...)] into #[stable(...)]?

Edit: Done.

@hch12907
Copy link
Contributor Author

hch12907 commented May 16, 2020

Uh, I'll rebase it properly in a moment.
Edit: Done

@Dylan-DPC-zz
Copy link

r? @Amanieu

@Amanieu
Copy link
Member

Amanieu commented May 20, 2020

I'm not really sure if ordering addresses makes sense, but since we already have the precedent in IpAddr I think this is fine.

@rfcbot fcp merge

@Amanieu Amanieu added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 20, 2020
@Amanieu
Copy link
Member

Amanieu commented May 20, 2020

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented May 20, 2020

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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 rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels May 20, 2020
@dtolnay
Copy link
Member

dtolnay commented May 20, 2020

This FCP covers:

// heterogeneous PartialEq
impl PartialEq<SocketAddr> for SocketAddrV4 {...}
impl PartialEq<SocketAddr> for SocketAddrV6 {...}
impl PartialEq<SocketAddrV4> for SocketAddr {...}
impl PartialEq<SocketAddrV6> for SocketAddr {...}

// Ord
impl Ord for SocketAddr {...}
impl Ord for SocketAddrV4 {...}
impl Ord for SocketAddrV6 {...}

// homogeneous PartialOrd
impl PartialOrd<SocketAddr> for SocketAddr {...}
impl PartialOrd<SocketAddrV4> for SocketAddrV4 {...}
impl PartialOrd<SocketAddrV6> for SocketAddrV6 {...}

// heterogeneous PartialOrd
impl PartialOrd<SocketAddr> for SocketAddrV4 {...}
impl PartialOrd<SocketAddr> for SocketAddrV6 {...}
impl PartialOrd<SocketAddrV4> for SocketAddr {...}
impl PartialOrd<SocketAddrV6> for SocketAddr {...}

The first 3 groups looks fine to me.

Is there any use case for the last group? What kind of code would reasonably want to use those?

@dtolnay
Copy link
Member

dtolnay commented May 21, 2020

Just gonna register my skepticism in #72239 (comment).

@rfcbot concern heterogeneous PartialOrd

I think those impls could cause more harm than good, where a refactor turns something that used to be a homogeneous < into an unintentional heterogeneous < that is always true or always false because it's comparing V6s to a constant V4 for example.

@hch12907
Copy link
Contributor Author

I implemented it because IpAddr has had similar implementations too. (#38464)

Though I agree that its use cases are very niche and generally not useful, it may be surprising for users to find that their code fails to compile, when they find-and-replace IpAddr* with SocketAddr*.

@hch12907
Copy link
Contributor Author

Removed heterogeneous ordering as per @dtolnay's suggestion and updated the tests a little bit. The PR should be ready for further (and hopefully final!) review now.

nytopop added a commit to nytopop/blip that referenced this pull request May 24, 2020
This makes it possible to search a MultiNodeCut by SocketAddr without
doing a linear scan.

Unfortunately, SocketAddr doesn't implement Ord, so we have to base the
sort on tuples of (ip, port).

related: rust-lang/rust#72239
@dtolnay
Copy link
Member

dtolnay commented May 24, 2020

@rfcbot resolve heterogeneous PartialOrd
@rfcbot reviewed

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label May 24, 2020
@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label May 24, 2020
@rfcbot
Copy link

rfcbot commented May 24, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@dtolnay dtolnay added the relnotes Marks issues that should be documented in the release notes of the next release. label May 28, 2020
@dtolnay dtolnay added this to the 1.45 milestone May 28, 2020
@dtolnay
Copy link
Member

dtolnay commented May 28, 2020

@bors r+

@bors
Copy link
Contributor

bors commented May 28, 2020

📌 Commit d1bc8ad has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 29, 2020
Rollup of 12 pull requests

Successful merges:

 - rust-lang#72239 (Implement PartialOrd and Ord for SocketAddr*)
 - rust-lang#72466 (Stabilize str_strip feature)
 - rust-lang#72605 (Add working example for E0617 explanation)
 - rust-lang#72636 (Cleanup `Resolver::<clone|into>_outputs` methods)
 - rust-lang#72645 (Add myself to .mailmap)
 - rust-lang#72667 (expand unaligned_references test)
 - rust-lang#72670 (Fix incorrect comment in generator test)
 - rust-lang#72674 (Clippy should always build)
 - rust-lang#72682 (Add test for rust-lang#66930)
 - rust-lang#72695 (update data layout for illumos x86)
 - rust-lang#72697 (Remove rustc-ux-guidelines)
 - rust-lang#72702 (rustc_lint: Remove `unused_crate_dependencies` from the `unused` group)

Failed merges:

r? @ghost
@bors bors merged commit b18c55b into rust-lang:master May 29, 2020
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jun 3, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jun 13, 2020
Revert heterogeneous SocketAddr PartialEq impls

Originally added in rust-lang#72239.

These lead to inference regressions (mostly in tests) in code that looks like:

```rust
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
```

That compiles as of stable 1.44.0 but fails in beta with:

```console
error[E0284]: type annotations needed
 --> src/main.rs:3:41
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
  |                                         ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse`
  |
  = note: cannot satisfy `<_ as std::str::FromStr>::Err == _`
help: consider specifying the type argument in the method call
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap());
  |
```

Closes rust-lang#73242.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jun 14, 2020
Revert heterogeneous SocketAddr PartialEq impls

Originally added in rust-lang#72239.

These lead to inference regressions (mostly in tests) in code that looks like:

```rust
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
```

That compiles as of stable 1.44.0 but fails in beta with:

```console
error[E0284]: type annotations needed
 --> src/main.rs:3:41
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
  |                                         ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse`
  |
  = note: cannot satisfy `<_ as std::str::FromStr>::Err == _`
help: consider specifying the type argument in the method call
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap());
  |
```

Closes rust-lang#73242.
zonyitoo referenced this pull request in shadowsocks/shadowsocks-rust Jun 15, 2020
ACL checking may requires lots of calculation and network I/O (DNS resolution)
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 15, 2020
Revert heterogeneous SocketAddr PartialEq impls

Originally added in rust-lang#72239.

These lead to inference regressions (mostly in tests) in code that looks like:

```rust
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
```

That compiles as of stable 1.44.0 but fails in beta with:

```console
error[E0284]: type annotations needed
 --> src/main.rs:3:41
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
  |                                         ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse`
  |
  = note: cannot satisfy `<_ as std::str::FromStr>::Err == _`
help: consider specifying the type argument in the method call
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap());
  |
```

Closes rust-lang#73242.
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 15, 2020
Revert heterogeneous SocketAddr PartialEq impls

Originally added in rust-lang#72239.

These lead to inference regressions (mostly in tests) in code that looks like:

```rust
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
```

That compiles as of stable 1.44.0 but fails in beta with:

```console
error[E0284]: type annotations needed
 --> src/main.rs:3:41
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse().unwrap());
  |                                         ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse`
  |
  = note: cannot satisfy `<_ as std::str::FromStr>::Err == _`
help: consider specifying the type argument in the method call
  |
3 |     assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap());
  |
```

Closes rust-lang#73242.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 6, 2020
While here clean up all pkglint warnings.  Changes since 1.44.1:

Version 1.45.2 (2020-08-03)
==========================

* [Fix bindings in tuple struct patterns][74954]
* [Fix track_caller integration with trait objects][74784]

[74954]: rust-lang/rust#74954
[74784]: rust-lang/rust#74784

Version 1.45.1 (2020-07-30)
==========================

* [Fix const propagation with references.][73613]
* [rustfmt accepts rustfmt_skip in cfg_attr again.][73078]
* [Avoid spurious implicit region bound.][74509]
* [Install clippy on x.py install][74457]

[73613]: rust-lang/rust#73613
[73078]: rust-lang/rust#73078
[74509]: rust-lang/rust#74509
[74457]: rust-lang/rust#74457

Version 1.45.0 (2020-07-16)
==========================

Language
--------
- [Out of range float to int conversions using `as` has been defined as a saturating
  conversion.][71269] This was previously undefined behaviour, but you can use the
   `{f64, f32}::to_int_unchecked` methods to continue using the current behaviour, which
   may be desirable in rare performance sensitive situations.
- [`mem::Discriminant<T>` now uses `T`'s discriminant type instead of always
  using `u64`.][70705]
- [Function like procedural macros can now be used in expression, pattern, and  statement
  positions.][68717] This means you can now use a function-like procedural macro
  anywhere you can use a declarative (`macro_rules!`) macro.

Compiler
--------
- [You can now override individual target features through the `target-feature`
  flag.][72094] E.g. `-C target-feature=+avx2 -C target-feature=+fma` is now
  equivalent to `-C target-feature=+avx2,+fma`.
- [Added the `force-unwind-tables` flag.][69984] This option allows
  rustc to always generate unwind tables regardless of panic strategy.
- [Added the `embed-bitcode` flag.][71716] This codegen flag allows rustc
  to include LLVM bitcode into generated `rlib`s (this is on by default).
- [Added the `tiny` value to the `code-model` codegen flag.][72397]
- [Added tier 3 support\* for the `mipsel-sony-psp` target.][72062]
- [Added tier 3 support for the `thumbv7a-uwp-windows-msvc` target.][72133]

\* Refer to Rust's [platform support page][forge-platform-support] for more
information on Rust's tiered platform support.


Libraries
---------
- [`net::{SocketAddr, SocketAddrV4, SocketAddrV6}` now implements `PartialOrd`
  and `Ord`.][72239]
- [`proc_macro::TokenStream` now implements `Default`.][72234]
- [You can now use `char` with
  `ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo}` to iterate over
  a range of codepoints.][72413] E.g.
  you can now write the following;
  ```rust
  for ch in 'a'..='z' {
      print!("{}", ch);
  }
  println!();
  // Prints "abcdefghijklmnopqrstuvwxyz"
  ```
- [`OsString` now implements `FromStr`.][71662]
- [The `saturating_neg` method as been added to all signed integer primitive
  types, and the `saturating_abs` method has been added for all integer
  primitive types.][71886]
- [`Arc<T>`, `Rc<T>` now implement  `From<Cow<'_, T>>`, and `Box` now
  implements `From<Cow>` when `T` is `[T: Copy]`, `str`, `CStr`, `OsStr`,
  or `Path`.][71447]
- [`Box<[T]>` now implements `From<[T; N]>`.][71095]
- [`BitOr` and `BitOrAssign` are implemented for all `NonZero`
  integer types.][69813]
- [The `fetch_min`, and `fetch_max` methods have been added to all atomic
  integer types.][72324]
- [The `fetch_update` method has been added to all atomic integer types.][71843]

Stabilized APIs
---------------
- [`Arc::as_ptr`]
- [`BTreeMap::remove_entry`]
- [`Rc::as_ptr`]
- [`rc::Weak::as_ptr`]
- [`rc::Weak::from_raw`]
- [`rc::Weak::into_raw`]
- [`str::strip_prefix`]
- [`str::strip_suffix`]
- [`sync::Weak::as_ptr`]
- [`sync::Weak::from_raw`]
- [`sync::Weak::into_raw`]
- [`char::UNICODE_VERSION`]
- [`Span::resolved_at`]
- [`Span::located_at`]
- [`Span::mixed_site`]
- [`unix::process::CommandExt::arg0`]

Cargo
-----

Misc
----
- [Rustdoc now supports strikethrough text in Markdown.][71928] E.g.
  `~~outdated information~~` becomes "~~outdated information~~".
- [Added an emoji to Rustdoc's deprecated API message.][72014]

Compatibility Notes
-------------------
- [Trying to self initialize a static value (that is creating a value using
  itself) is unsound and now causes a compile error.][71140]
- [`{f32, f64}::powi` now returns a slightly different value on Windows.][73420]
  This is due to changes in LLVM's intrinsics which `{f32, f64}::powi` uses.
- [Rustdoc's CLI's extra error exit codes have been removed.][71900] These were
  previously undocumented and not intended for public use. Rustdoc still provides
  a non-zero exit code on errors.

Internals Only
--------------
- [Make clippy a git subtree instead of a git submodule][70655]
- [Unify the undo log of all snapshot types][69464]

[73420]: rust-lang/rust#73420
[72324]: rust-lang/rust#72324
[71843]: rust-lang/rust#71843
[71886]: rust-lang/rust#71886
[72234]: rust-lang/rust#72234
[72239]: rust-lang/rust#72239
[72397]: rust-lang/rust#72397
[72413]: rust-lang/rust#72413
[72014]: rust-lang/rust#72014
[72062]: rust-lang/rust#72062
[72094]: rust-lang/rust#72094
[72133]: rust-lang/rust#72133
[71900]: rust-lang/rust#71900
[71928]: rust-lang/rust#71928
[71662]: rust-lang/rust#71662
[71716]: rust-lang/rust#71716
[71447]: rust-lang/rust#71447
[71269]: rust-lang/rust#71269
[71095]: rust-lang/rust#71095
[71140]: rust-lang/rust#71140
[70655]: rust-lang/rust#70655
[70705]: rust-lang/rust#70705
[69984]: rust-lang/rust#69984
[69813]: rust-lang/rust#69813
[69464]: rust-lang/rust#69464
[68717]: rust-lang/rust#68717
[`Arc::as_ptr`]: https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#method.as_ptr
[`BTreeMap::remove_entry`]: https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html#method.remove_entry
[`Rc::as_ptr`]: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.as_ptr
[`rc::Weak::as_ptr`]: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html#method.as_ptr
[`rc::Weak::from_raw`]: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html#method.from_raw
[`rc::Weak::into_raw`]: https://doc.rust-lang.org/stable/std/rc/struct.Weak.html#method.into_raw
[`sync::Weak::as_ptr`]: https://doc.rust-lang.org/stable/std/sync/struct.Weak.html#method.as_ptr
[`sync::Weak::from_raw`]: https://doc.rust-lang.org/stable/std/sync/struct.Weak.html#method.from_raw
[`sync::Weak::into_raw`]: https://doc.rust-lang.org/stable/std/sync/struct.Weak.html#method.into_raw
[`str::strip_prefix`]: https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_prefix
[`str::strip_suffix`]: https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_suffix
[`char::UNICODE_VERSION`]: https://doc.rust-lang.org/stable/std/char/constant.UNICODE_VERSION.html
[`Span::resolved_at`]: https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.resolved_at
[`Span::located_at`]: https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.located_at
[`Span::mixed_site`]: https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.mixed_site
[`unix::process::CommandExt::arg0`]: https://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html#tymethod.arg0
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 24, 2023
…shtriplett

Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`

Fixes rust-lang#116711

The main pain of this PR is to fix the buggy impl of `Ord` for `SocketAddrV6`, which ignored half of the fields (while `PartialEq` is derived):
https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L99-L106

https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L676

For me it looks like a simple copy-paste error made in rust-lang#72239 (copy from v4 impl) (cc `@hch12907),` as I don't see this behavior being mentioned anywhere on the PR and it also does not respect `cmp` trait "rules". I also do not see any reasons for those impls to _not_ be derived.

It's a shame we did not notice this for 28 versions/3 years. I guess this is a bug fix, but I'm not sure what the process here should be.

r? libs
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 24, 2023
Rollup merge of rust-lang#116714 - WaffleLapkin:order-the-order, r=joshtriplett

Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`

Fixes rust-lang#116711

The main pain of this PR is to fix the buggy impl of `Ord` for `SocketAddrV6`, which ignored half of the fields (while `PartialEq` is derived):
https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L99-L106

https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L676

For me it looks like a simple copy-paste error made in rust-lang#72239 (copy from v4 impl) (cc `@hch12907),` as I don't see this behavior being mentioned anywhere on the PR and it also does not respect `cmp` trait "rules". I also do not see any reasons for those impls to _not_ be derived.

It's a shame we did not notice this for 28 versions/3 years. I guess this is a bug fix, but I'm not sure what the process here should be.

r? libs
@dtolnay dtolnay self-assigned this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why doesn't std::net::SocketAddr implement std::cmp::Ord and std::cmp::PartialOrd?
9 participants