Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums chapter from the Guide contains incorrect example code #17675

Closed
Valve opened this issue Oct 1, 2014 · 3 comments
Closed

Enums chapter from the Guide contains incorrect example code #17675

Valve opened this issue Oct 1, 2014 · 3 comments

Comments

@Valve
Copy link

Valve commented Oct 1, 2014

Currently it is:

enum Ordering {
    Less,
    Equal,
    Greater,
}

fn cmp(a: int, b: int) -> Ordering {
    if a < b { Less }
    else if a > b { Greater }
    else { Equal }
}

fn main() {
    let x = 5i;
    let y = 10i;

    let ordering = cmp(x, y);

    if ordering == Less {
        println!("less");
    } else if ordering == Greater {
        println!("greater");
    } else if ordering == Equal {
        println!("equal");
    }
}

This does not compile:

error: binary operation `==` cannot be applied to type `Ordering`

Required modifications:

#[deriving(PartialEq)]
enum Ordering {
    Less,
    Equal,
    Greater,
}
@steveklabnik
Copy link
Member

As the guide says, this enum is provided by Rust, and so you're not supposed to define it.

@href
Copy link

href commented Oct 2, 2014

For what it's worth, I stumbled upon this issue as well while learning Rust. I tried an example with my own Enum and the error given by the compiler lead me here.

@jaxx
Copy link

jaxx commented Nov 2, 2014

same here,

although this works:

fn main()
{
    let x = 5i;
    let y = 10i;

    match cmp(x, y)
    {
        Less => println!("less"),
        Equal => println!("equal"),
        Greater => println!("greater")
    }
}

lnicola pushed a commit to lnicola/rust that referenced this issue Jul 28, 2024
…mmands-config, r=lnicola

Remove lens.forceCustomCommands config

Closes rust-lang/rust-analyzer#17643
A very simple PR that removes the lens.forceCustomCommands config feature without side effects.
RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 1, 2024
…mmands-config, r=lnicola

Remove lens.forceCustomCommands config

Closes rust-lang/rust-analyzer#17643
A very simple PR that removes the lens.forceCustomCommands config feature without side effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants