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

Better diagnostics for accidentally nested block comments #95283

Closed
jrmuizel opened this issue Mar 24, 2022 · 2 comments · Fixed by #95859
Closed

Better diagnostics for accidentally nested block comments #95283

jrmuizel opened this issue Mar 24, 2022 · 2 comments · Fixed by #95859
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. 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

@jrmuizel
Copy link
Contributor

jrmuizel commented Mar 24, 2022

Given:

fn main ()
{
    /*
    //bland
    //weconwec'iwe
    
    //wec'oinwec'oinwec
    
    //wec
    //wecponjwec
    
    
    //wecponwec
    //let foo: &u32 = panic!();
    //*foo = 12
    //help out
    //more stuff
    */
}

The compiler says:

error[[E0758]](https://doc.rust-lang.org/stable/error-index.html#E0758): unterminated block comment
  [--> src/main.rs:3:5
](https://play.rust-lang.org/#)   |
3  | /     /*
4  | |     //bland
5  | |     //weconwec'iwe
6  | |     
...  |
18 | |     */
19 | | }
   | |_^

For more information about this error, try `rustc --explain E0758`.
error: could not compile `playground` due to previous error

This initially confused me quite a bit because I couldn't figure out why Rust wasn't seeing block comment terminator. Eventually, I realized that the line //*foo = 12 changed from being a commented out line, to starting a nested block comment. Since block comments nest in Rust, I'm used to commenting out blocks without worrying about what's inside of them which made this behaviour surprising.

I'm not sure how practical it is, but it would be cool if we could check for comments like //*foo = 12 in block comments to suggest them as the source of the problem.

@jrmuizel jrmuizel 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 Mar 24, 2022
@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Mar 24, 2022
@b-ncMN
Copy link
Contributor

b-ncMN commented Mar 25, 2022

@rustbot claim

@b-ncMN b-ncMN removed their assignment Mar 28, 2022
@yue4u
Copy link
Contributor

yue4u commented Apr 9, 2022

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 14, 2022
…comment, r=petrochenkov

Improve diagnostics for unterminated nested block comment

close rust-lang#95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 14, 2022
…comment, r=petrochenkov

Improve diagnostics for unterminated nested block comment

close rust-lang#95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 14, 2022
…comment, r=petrochenkov

Improve diagnostics for unterminated nested block comment

close rust-lang#95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 15, 2022
…comment, r=petrochenkov

Improve diagnostics for unterminated nested block comment

close rust-lang#95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 15, 2022
…comment, r=petrochenkov

Improve diagnostics for unterminated nested block comment

close rust-lang#95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 16, 2022
…comment, r=petrochenkov

Improve diagnostics for unterminated nested block comment

close rust-lang#95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
@bors bors closed this as completed in 946d76e Apr 16, 2022
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 D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

4 participants