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

Improve Ord violation help #128273

Merged
merged 6 commits into from
Aug 10, 2024
Merged

Conversation

Voultapher
Copy link
Contributor

Recent experience in #128083 showed that the panic message when an Ord violation is detected by the new sort implementations can be confusing. So this PR aims to improve it, together with minor bug fixes in the doc comments for sort*, sort_unstable* and select_nth_unstable*.

Is it possible to get these changes into the 1.81 release? It doesn't change behavior and would greatly help when users encounter this panic for the first time, which they may after upgrading to 1.81.

Tagging @orlp

The new sort implementations have the ability to
detect Ord violations in many cases. This commit
improves the message in a way that should help
users realize what went wrong in their program.
…ble*

- Move panic information into # Panics section
- Fix mentions of T: Ord that should be compare
- Add missing information
@Voultapher Voultapher changed the title Improve ord violation help Improve Ord violation help Jul 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2024

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 27, 2024
@compiler-errors compiler-errors added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 27, 2024
@tgross35
Copy link
Contributor

tgross35 commented Jul 27, 2024

Thanks for the followup, this will be great to have.

For all the uses of "total order", could we link somewhere? Either the Wikipedia page, or link somewhere on the Ord page.

Maybe Ord should just get a "total order" section that shows an example incorrect implementation since it's not always easy to compare code to equations.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already anticipate someone is going to read this note and say "but that can't happen because K is Ord and Ord is a total order". This should be clearer about that case.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, noticed some typos also.

@Voultapher
Copy link
Contributor Author

Thanks for the followup, this will be great to have.

For all the uses of "total order", could we link somewhere? Either the Wikipedia page, or link somewhere on the Ord page.

Maybe Ord should just get a "total order" section that shows an example incorrect implementation since it's not always easy to compare code to equations.

Good idea, currently the Ord docs links to wikipedia, we could do the same. That said doing so might seem a little intimidating to users unfamiliar with the matter. I like the idea of having concrete code that demonstrates the ideas at play.

@Voultapher Voultapher changed the title Improve Ord violation help Improve Ord violation help Jul 31, 2024
- Use if the implementation of [`Ord`] for `T`
  language
- Link to total order wiki page
- Rework total order help and examples
- Improve language to be more precise and less
  prone to misunderstandings.
- Fix usage of `sort_unstable_by` in `sort_by`
  example
- Fix missing author mention
- Use more consistent example input for sort
- Use more idiomatic assert_eq! in examples
- Use more natural "comparison function" language
  instead of "comparator function"
@Amanieu Amanieu added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jul 31, 2024
@Voultapher
Copy link
Contributor Author

Changes since last review:

  • Use if the implementation of [Ord] for T
    language
  • Link to total order wiki page
  • Rework total order help and examples
  • Improve language to be more precise and less
    prone to misunderstandings.
  • Fix usage of sort_unstable_by in sort_by
    example
  • Fix missing author mention
  • Use more consistent example input for sort
  • Use more idiomatic assert_eq! in examples
  • Use more natural "comparison function" language
    instead of "comparator function"
  • Hide sort module

@Voultapher
Copy link
Contributor Author

Voultapher commented Aug 1, 2024

There are something like 10 places that document sort usage, so chances are I missed something, please carefully review for typos and mistakes.

@Voultapher
Copy link
Contributor Author

Voultapher commented Aug 1, 2024

I've also started making changes to the Ord docs to better help people understand how to correctly derive and implement them, but that has grown out of scope and I plan on creating a separate PR for it. The sort docs link people to relevant information and surface some of it where sensible, but it's a tricky balance between too little information and linking to the relevant places and overloading and duplicating information in the sort docs. I hope the current iteration strikes a decent balance between the two.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I noticed some remaining nits. They're just typos or non-blocking concerns because the original wording here was signed-off-on by libs already and they don't necessarily relate directly to the concern of the "total order" requirement.

@joboet joboet assigned workingjubilee and unassigned joboet Aug 1, 2024
@Voultapher
Copy link
Contributor Author

@workingjubilee thanks for the detailed review so far.

@workingjubilee
Copy link
Member

Okie dokie! I think that everything else is stuff that we can defer to later. Thank you everyone.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 5, 2024

📌 Commit 613155c has been approved by workingjubilee

It is now in the queue for this repository.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 6, 2024
…elp, r=workingjubilee

Improve `Ord` violation help

Recent experience in rust-lang#128083 showed that the panic message when an Ord violation is detected by the new sort implementations can be confusing. So this PR aims to improve it, together with minor bug fixes in the doc comments for sort*, sort_unstable* and select_nth_unstable*.

Is it possible to get these changes into the 1.81 release? It doesn't change behavior and would greatly help when users encounter this panic for the first time, which they may after upgrading to 1.81.

Tagging `@orlp`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#122792 (Stabilize `min_exhaustive_patterns`)
 - rust-lang#124944 (On trait bound mismatch, detect multiple crate versions in dep tree)
 - rust-lang#128273 (Improve `Ord` violation help)
 - rust-lang#128406 (implement BufReader::peek)
 - rust-lang#128539 (Forbid unused unsafe in vxworks-specific std modules)
 - rust-lang#128692 (Add a triagebot mention for `library/Cargo.lock`)
 - rust-lang#128710 (Don't ICE when getting an input file name's stem fails)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 6, 2024
…elp, r=workingjubilee

Improve `Ord` violation help

Recent experience in rust-lang#128083 showed that the panic message when an Ord violation is detected by the new sort implementations can be confusing. So this PR aims to improve it, together with minor bug fixes in the doc comments for sort*, sort_unstable* and select_nth_unstable*.

Is it possible to get these changes into the 1.81 release? It doesn't change behavior and would greatly help when users encounter this panic for the first time, which they may after upgrading to 1.81.

Tagging ``@orlp``
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#125048 (PinCoerceUnsized trait into core)
 - rust-lang#128273 (Improve `Ord` violation help)
 - rust-lang#128406 (implement BufReader::peek)
 - rust-lang#128539 (Forbid unused unsafe in vxworks-specific std modules)
 - rust-lang#128687 (interpret: refactor function call handling to be better-abstracted)
 - rust-lang#128692 (Add a triagebot mention for `library/Cargo.lock`)
 - rust-lang#128710 (Don't ICE when getting an input file name's stem fails)
 - rust-lang#128718 (Consider `cfg_attr` checked by `CheckAttrVisitor`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#125048 (PinCoerceUnsized trait into core)
 - rust-lang#128273 (Improve `Ord` violation help)
 - rust-lang#128406 (implement BufReader::peek)
 - rust-lang#128539 (Forbid unused unsafe in vxworks-specific std modules)
 - rust-lang#128687 (interpret: refactor function call handling to be better-abstracted)
 - rust-lang#128692 (Add a triagebot mention for `library/Cargo.lock`)
 - rust-lang#128710 (Don't ICE when getting an input file name's stem fails)
 - rust-lang#128718 (Consider `cfg_attr` checked by `CheckAttrVisitor`)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
guess this failed here: #128739 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 6, 2024
@Voultapher
Copy link
Contributor Author

While I can't reproduce the issue with ./x.py --stage 0 test linkchecker html-checker I made small tweak based on the error message that should hopefully fix the issue.

@workingjubilee
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 9, 2024

📌 Commit 1be60b5 has been approved by workingjubilee

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 9, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 10, 2024
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128273 (Improve `Ord` violation help)
 - rust-lang#128807 (run-make: explaing why fmt-write-bloat is ignore-windows)
 - rust-lang#128903 (rustdoc-json-types `Discriminant`: fix typo)
 - rust-lang#128905 (gitignore: Add Zed and Helix editors)
 - rust-lang#128908 (diagnostics: do not warn when a lifetime bound infers itself)
 - rust-lang#128909 (Fix dump-ice-to-disk for RUSTC_ICE=0 users)
 - rust-lang#128910 (Differentiate between methods and associated functions in diagnostics)
 - rust-lang#128923 ([rustdoc] Stop showing impl items for negative impls)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 65875b2 into rust-lang:master Aug 10, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 10, 2024
Rollup merge of rust-lang#128273 - Voultapher:improve-ord-violation-help, r=workingjubilee

Improve `Ord` violation help

Recent experience in rust-lang#128083 showed that the panic message when an Ord violation is detected by the new sort implementations can be confusing. So this PR aims to improve it, together with minor bug fixes in the doc comments for sort*, sort_unstable* and select_nth_unstable*.

Is it possible to get these changes into the 1.81 release? It doesn't change behavior and would greatly help when users encounter this panic for the first time, which they may after upgrading to 1.81.

Tagging `@orlp`
@Voultapher
Copy link
Contributor Author

I see this PR hasn't made its way into the beta yet, what is needed for that?

@ChrisDenton
Copy link
Member

Patience. Merging into beta is a manual process. This PR is labelled as beta-accepted so it'll be merged (possibly along with other beta-accepted PRs) the next time someone does the backports.

@Voultapher Voultapher deleted the improve-ord-violation-help branch August 12, 2024 12:35
@cuviper cuviper modified the milestones: 1.82.0, 1.81.0 Aug 13, 2024
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 15, 2024
[beta] backports and bump stage0

- Disable jump threading of float equality rust-lang#128271
- Normalize when equating `dyn` tails in MIR borrowck rust-lang#128694
- Improve `Ord` violation help rust-lang#128273
- bump stage0 to stable 1.80.1
- Revert rust-lang#125915 on beta rust-lang#128760
- derive(SmartPointer): register helper attributes rust-lang#128925
- Fix bug in `Parser::look_ahead`. rust-lang#128994

r? cuviper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.