rust-lang / rust-lang/rust

Tracking Issue for `cmp_splat` (Variadic `min` and `max`)

Open
#160,728 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue F-splat S-tracking-needs-to-bake T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(cmp_splat)]
Zulip: #t-libs-api/api-changes > variadic min/max

This is a tracking issue for variadic cmp::min and cmp::max functions. Currently, these are separate functions named smallest and largest. To allow variadic support, #![feature(splat)] is enabled in core. See rust-lang/rust#153629 for further details.

Public API
// core::cmp

// Private implementation detail
impl(self) const trait TupleReduce: Tuple {
    type Item;
    fn reduce<F: [const] Destruct + [const] FnMut(Self::Item, Self::Item) -> Self::Item>(self, f: F) -> Self::Item;
}

impl<T> TupleReduce for (T, ...) { /* ... */ }

#[must_use]
pub const fn smallest<T: [const] Ord + [const] Destruct>(
    #[rustc_splat] vals: impl [const] TupleReduce<Item = T>,
) -> T;

#[must_use]
pub const fn largest<T: [const] Ord + [const] Destruct>(
    #[rustc_splat] vals: impl [const] TupleReduce<Item = T>,
) -> T;

Note that with #[rustc_splat], the signature of smallest and largest is any of fn(T) -> T through to fn(T, T, ..) -> T (up to twelve arguments). Twelve has been chosen as an arbitrary limit and can be changed.

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • ACP: rust-lang/libs-team#848
  • Implementation: #160687
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • Should we replace min and max (and their _by(_key) alternatives), or offer these new functions under a separate name?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the core::cmp public API and the checked implementation entry in #160687, then review the linked Zulip discussion and the unresolved naming question. Done means resolving the API choice, completing the final comment period, and opening a stabilization PR.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.