rust-lang / rust-lang/rust

Suggest Option::max on non Ord T instead of call .into_iter()

Open
#149,669 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
enum NonOrd {
    A,
    B
}

fn main() {
    let a = Some(NonOrd::A);
    let b = Some(NonOrd::B);
    
    let _ = a.max(b);
    let _ = Option::max(a, b);
}
Current output
error[E0599]: no method named `max` found for enum `Option<NonOrd>` in the current scope
  --> src/main.rs:10:15
   |
10 |     let _ = a.max(b);
   |               ^^^ `Option<NonOrd>` is not an iterator
   |
help: call `.into_iter()` first
   |
10 |     let _ = a.into_iter().max(b);
   |               ++++++++++++
Desired output
Method Option::max exists but the trait `Ord` is not implemented for `NonOrd`
Rationale and extra context

It is very confusing that rustc suggests wrapping Option into an iterator to then call Iterator::max on it.

Other cases

Rust Version
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5
Anything else?

No response

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

Reproduce the diagnostic with the Rust example in the issue and compare the method-call and associated-function cases. No source file or test is named, so locating the relevant rustc diagnostic and suggestion handling is the first step. Done means a non-Ord Option value receives an Ord-related message instead of an .into_iter() suggestion.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.