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

“help: place this code inside a block” is… pretty confusing #30037

Closed
nagisa opened this issue Nov 24, 2015 · 10 comments
Closed

“help: place this code inside a block” is… pretty confusing #30037

nagisa opened this issue Nov 24, 2015 · 10 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@nagisa
Copy link
Member

nagisa commented Nov 24, 2015

fn main() {
    let n = 1;
    if 5 == {
        println!("five");
    }
}

reports

<anon>:6:1: 6:2 error: expected `{`, found `}`
<anon>:6 }
         ^
<anon>:6:1: 6:2 help: place this code inside a block

The help message is pretty confusing. Which code it has in mind? There’s no code which you could place into a block to fix this error either, as far as I can see.

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 24, 2015
@antoyo
Copy link
Contributor

antoyo commented Nov 26, 2015

This help message makes sense with the following code:

fn main() {
    let n = 1;
    if n == 5
        println!("five");
}

because it needs curly braces for the body of the condition.

@Aatch
Copy link
Contributor

Aatch commented Nov 27, 2015

One possible fix could be to attempt to parse an expression and only show the help message if it succeeded. So since } is not a valid expression, it won't work work. This would catch the case we want to, demonstrated by @antoyo, while hopefully avoiding the useless help message.

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@estebank
Copy link
Contributor

This ticket can be closed, given:

fn main() {
    let n = 1;
    if 5 == 1
        println!("five");
}
fn foo() {
    let n = 1;
    if 5 == {
        println!("five");
    }
}

Diagnostics:

error: expected `{`, found `println`
 --> <anon>:4:9
  |
4 |         println!("five");
  |         ^^^^^^^
  |
help: try placing this code inside a block
  |         { println!("five") }

error: expected `{`, found `}`
  --> <anon>:11:1
   |
11 | }
   | ^

CC @jonathandturner

@sophiajt
Copy link
Contributor

Definitely a bit better.

@antoyo
Copy link
Contributor

antoyo commented Mar 24, 2017

Well, it does not seem to fix the issue in the first post.
It is the same error message, isn't it?

@sophiajt
Copy link
Contributor

@antoyo - this one shows the code to put in the block

@antoyo
Copy link
Contributor

antoyo commented Mar 24, 2017

What I meant is that the error from the first post:

fn main() {
   let n = 1;
   if 5 == {
       println!("five");
   }
}

reports

<anon>:6:1: 6:2 error: expected `{`, found `}`
<anon>:6 }
        ^
<anon>:6:1: 6:2 help: place this code inside a block

does not seem to have changed:

error: expected `{`, found `}`
 --> <anon>:11:1
   |
11 | }
   | ^

@sophiajt
Copy link
Contributor

@antoyo - that part of the error is still correct, but there's an additional part now which gives more information:

error: expected `{`, found `println`
 --> <anon>:4:9
  |
4 |         println!("five");
  |         ^^^^^^^
  |
help: try placing this code inside a block
  |         { println!("five") }

@antoyo
Copy link
Contributor

antoyo commented Mar 24, 2017

My understanding is that this error message is for the code in the second post:

fn main() {
    let n = 1;
    if n == 5
        println!("five");
}

But the code from the first post still gives the same error, right?

@estebank
Copy link
Contributor

@antoyo #30035 is still open, this was a follow up only about the help: place this code inside a block message not being relevant.

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
Projects
None yet
Development

No branches or pull requests

7 participants