Skip to content

Add Discriminant::unstable_cmp - #164231

Closed
bushrat011899 wants to merge 1 commit into
rust-lang:mainfrom
bushrat011899:discriminant_unstable_cmp
Closed

bushrat011899 wants to merge 1 commit into
rust-lang:mainfrom
bushrat011899:discriminant_unstable_cmp

Conversation

@bushrat011899

@bushrat011899 bushrat011899 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

ACP: rust-lang/libs-team#925
Tracking Issue: #165438
Supersedes: #106418
Zulip Discussion: #t-libs > Impl Partial/Ord for Discriminant

Based on this concern on the implementation of Partial/Ord for Discriminant, I'm proposing we instead offer an unstable_cmp function. This mirrors the fN::total_cmp function used to provide Ord-like functionality to f16/32/64/128 without actually guaranteeing the type itself is Ord.

Notes

  • No AI tooling of any kind was used during the creation of this PR.
  • The name unstable_cmp has been chosen to explicitly document at each usage that the ordering of Discriminant values is not stable and may change.
  • I have not created a tracking issue or ACP, but I'd be happy to upon request!
  • The function could be trivially made const, but that requires either making DiscriminantKind::Discriminant: const Ord or adding a fairly verbose where <T as DiscriminantKind>::Discriminant: [const] Ord to unstable_cmp. As such I'm deferring its inclusion. It would remain unstable until const_cmp is stabilized anyway.
  • The bounds on DiscriminantKind::Discriminant have been simplified by removing PartialEq and Clone, as they are implicitly included by Eq and Copy respectively. This also ensures that adding Ord does not cause rustfmt to wrap the line. See this comment for details.

@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 Oct 12, 2026
@rustbot

rustbot commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum

Comment thread library/core/src/mem/mod.rs Resolved
@rust-log-analyzer

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the discriminant_unstable_cmp branch from efbd650 to 3dbf96a Compare October 12, 2026 23:33
Comment thread library/core/src/marker.rs Resolved
Comment thread library/core/src/mem/mod.rs Resolved
Comment thread library/core/src/mem/mod.rs Resolved
@bushrat011899
bushrat011899 force-pushed the discriminant_unstable_cmp branch 2 times, most recently from 6b272b0 to 242c4c1 Compare October 14, 2026 21:28
@rust-log-analyzer

This comment has been minimized.

Provides an unstable ordering between `Discriminant<T>` values.
@bushrat011899
bushrat011899 force-pushed the discriminant_unstable_cmp branch from 242c4c1 to 2044e73 Compare October 14, 2026 22:07

@Mark-Simulacrum Mark-Simulacrum left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this does need an ACP.

View changes since this review

Comment thread library/core/src/marker.rs Resolved
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2026
@bushrat011899

Copy link
Copy Markdown
Contributor Author

I think this does need an ACP.

Done!

@bushrat011899

Copy link
Copy Markdown
Contributor Author

ACP has been accepted. Noting here that #165443 has also been opened as an alternative implementation route. Keeping both PRs open as I don't believe there is consensus that one approach is clearly better than the other.

@rustbot label -S-waiting-on-ACP
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. labels Nov 4, 2026
@bushrat011899

Copy link
Copy Markdown
Contributor Author

Based on approval for the alternate implementation here, I'm going to close this PR. But it's easy enough to reopen if we want to revisit this and undo the other PR. Thanks to everyone who helped review this!

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 4, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…clarfonthey

Add `Discriminant::ord`

ACP: rust-lang/libs-team#925
Tracking Issue: rust-lang#165438
Alternative To: rust-lang#164231

This is an implementation for Option 2 from rust-lang#165438. This provides a new method `Discriminant::ord` which returns a new type, `DiscriminantOrd`, suitable for key comparison. This follows a philosophy similar to that of `Path::display` for providing functional through standard traits gated behind a wrapper. I've elected for the return type of `Discriminant::ord` to be named as was requested during the T-Libs meeting proposing this option, and I've chosen to implement all traits currently implemented by `Discriminant`, this could be reduced.

In comparison to rust-lang#164231, this has the advantage of allowing the storage of the discriminant in a structure and the deriving a `Partial/Ord` implementation.

# Notes

* No AI tooling of any kind was used during the creation of this PR.
* Chose the name `ord` as that appeared to be the generally preferred option, but alternatives may include `unstable_ord`, etc.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…clarfonthey

Add `Discriminant::ord`

ACP: rust-lang/libs-team#925
Tracking Issue: rust-lang#165438
Alternative To: rust-lang#164231

This is an implementation for Option 2 from rust-lang#165438. This provides a new method `Discriminant::ord` which returns a new type, `DiscriminantOrd`, suitable for key comparison. This follows a philosophy similar to that of `Path::display` for providing functional through standard traits gated behind a wrapper. I've elected for the return type of `Discriminant::ord` to be named as was requested during the T-Libs meeting proposing this option, and I've chosen to implement all traits currently implemented by `Discriminant`, this could be reduced.

In comparison to rust-lang#164231, this has the advantage of allowing the storage of the discriminant in a structure and the deriving a `Partial/Ord` implementation.

# Notes

* No AI tooling of any kind was used during the creation of this PR.
* Chose the name `ord` as that appeared to be the generally preferred option, but alternatives may include `unstable_ord`, etc.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…clarfonthey

Add `Discriminant::ord`

ACP: rust-lang/libs-team#925
Tracking Issue: rust-lang#165438
Alternative To: rust-lang#164231

This is an implementation for Option 2 from rust-lang#165438. This provides a new method `Discriminant::ord` which returns a new type, `DiscriminantOrd`, suitable for key comparison. This follows a philosophy similar to that of `Path::display` for providing functional through standard traits gated behind a wrapper. I've elected for the return type of `Discriminant::ord` to be named as was requested during the T-Libs meeting proposing this option, and I've chosen to implement all traits currently implemented by `Discriminant`, this could be reduced.

In comparison to rust-lang#164231, this has the advantage of allowing the storage of the discriminant in a structure and the deriving a `Partial/Ord` implementation.

# Notes

* No AI tooling of any kind was used during the creation of this PR.
* Chose the name `ord` as that appeared to be the generally preferred option, but alternatives may include `unstable_ord`, etc.
rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
Rollup merge of #165443 - bushrat011899:discriminant_ord, r=clarfonthey

Add `Discriminant::ord`

ACP: rust-lang/libs-team#925
Tracking Issue: #165438
Alternative To: #164231

This is an implementation for Option 2 from #165438. This provides a new method `Discriminant::ord` which returns a new type, `DiscriminantOrd`, suitable for key comparison. This follows a philosophy similar to that of `Path::display` for providing functional through standard traits gated behind a wrapper. I've elected for the return type of `Discriminant::ord` to be named as was requested during the T-Libs meeting proposing this option, and I've chosen to implement all traits currently implemented by `Discriminant`, this could be reduced.

In comparison to #164231, this has the advantage of allowing the storage of the discriminant in a structure and the deriving a `Partial/Ord` implementation.

# Notes

* No AI tooling of any kind was used during the creation of this PR.
* Chose the name `ord` as that appeared to be the generally preferred option, but alternatives may include `unstable_ord`, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

7 participants