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

improve match arm with semi-colon help suggestion #108472

Closed
pacberries opened this issue Feb 25, 2023 · 1 comment · Fixed by #108477
Closed

improve match arm with semi-colon help suggestion #108472

pacberries opened this issue Feb 25, 2023 · 1 comment · Fixed by #108477
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pacberries
Copy link

pacberries commented Feb 25, 2023

Code

use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    println!("Guess the number!");
    
    let secret_number = rand::thread_rng().gen_range(1..=100);
    println!("The secret number is: {secret_number}: ");

    println!("Please input your guess: ");

    let mut guess = String::new();

    io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");
    
    let guess: u32 = guess.trim().parse().expect("Please type a number: ");
   
    println!("You guessed: {guess}");
    match guess.cmp(&secret_number) {
        Ordering::Less => println!("Too small!");
        Ordering::Greater => println!("Too big!"),
        Ordering::Equal => println!("You won!"),
    }
}

Current output

23 |         Ordering::Less => println!("Too small!");
   |                        -- ^^^^^^^^^^^^^^^^^^^^^^- help: use a comma to end a `match` arm expression: `,`
   |                        |  |
   |                        |  this statement is not surrounded by a body
   |                        while parsing the `match` arm starting here

Desired output

error: `match` arm body without braces
  --> src/main.rs:23:27
   |
23 |         Ordering::Less => println!("Too small!");
   |                        -- ^^^^^^^^^^^^^^^^^^^^^^
   |                        |  |
   |                        |  this statement is not surrounded by a body
   |                        while parsing the `match` arm starting here
help: replace `;` with `,`
   |
23 |     Ordering::Less => println!("Too small!"),
   |

Rationale and extra context

The reason why it should be changed is because the new error message makes it clearer you should replace ; with ,. I was following the book, and I encountered this error. I didn't understand how to solve it and asked on the community discord, then a user in the community server then helped me and I managed to fix the error.

Other cases

No response

Anything else?

No response

@pacberries pacberries added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2023
@Noratrieb Noratrieb added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Feb 25, 2023
@y21
Copy link
Member

y21 commented Feb 26, 2023

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 26, 2023
…r=compiler-errors

Make `match` arm comma suggestion more clear

Fixes rust-lang#108472
compiler-errors added a commit to compiler-errors/rust that referenced this issue Feb 26, 2023
…r=compiler-errors

Make `match` arm comma suggestion more clear

Fixes rust-lang#108472
compiler-errors added a commit to compiler-errors/rust that referenced this issue Feb 26, 2023
…r=compiler-errors

Make `match` arm comma suggestion more clear

Fixes rust-lang#108472
@bors bors closed this as completed in 69b1b94 Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants