Skip to content

Alternative help for missing min/max functionΒ #76386

@leonardo-m

Description

@leonardo-m
fn main() {
    let x = 5;
    let y = 9;
    println!("{}", max(x, y));
}

With rustc (1.48.0-nightly 0d0f6b1 2020-09-03) gives:

error[E0425]: cannot find function `max` in this scope
 --> ...\test.rs:4:20
  |
4 |     println!("{}", max(x, y));
  |                    ^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 | use core::cmp::max;
  |
1 | use std::cmp::max;
  |

But it could suggest instead to use:

x.max(y)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions