Skip to content

Define Ord for &mut T if T is Ord #14074

Closed
@nikomatsakis

Description

@nikomatsakis

Currently, we don't define Ord for &mut T if T is Ord. But we should. As a curious side-effect, that permits you to write things like:

fn min<T:Ord>(x: T, y: T) -> T {
    if x < y { x } else { y }
}

pub fn main() {
    let mut x = 3;
    let mut y = 4;
    let mut z = 5;

    *min(&mut x, &mut y) = min(0, z);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions