Skip to content

Multiline comments ending in " lead to creation of line with only spaces #4312

New issue

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

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

Already on GitHub? # to your account

Closed
C4K3 opened this issue Jul 8, 2020 · 3 comments · Fixed by #4320
Closed

Multiline comments ending in " lead to creation of line with only spaces #4312

C4K3 opened this issue Jul 8, 2020 · 3 comments · Fixed by #4320

Comments

@C4K3
Copy link
Contributor

C4K3 commented Jul 8, 2020

Input

fn main() {
    /* " */
    println!("Hello, world!");
}

Output

fn main() {
    /* " */
    
    println!("Hello, world!");
}

(notice the blank line between the comment and the println, containing 4 spaces.

Expected output

Input unchanged.

Meta

  • rustfmt version: rustfmt 1.4.16-stable (939e164 2020-06-11)
  • From where did you install rustfmt?: rustup
@ayazhafiz
Copy link
Contributor

This seems to happen iff the comment is a /* comment with exactly " as its comment.

Putting two such comments in sequence leads to another "fun" bug: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=70c8eb3ed7416f5101dd5297cdd8c005 🙂

This is probably simple to fix since it seems to be such a specific case, but we should check if it's repro on master.

@C4K3
Copy link
Contributor Author

C4K3 commented Jul 8, 2020

It seems to be when it contains precisely one ". /* abc " */ and /* " abc */ both reproduce the issue.

ayazhafiz added a commit to ayazhafiz/rustfmt that referenced this issue Jul 11, 2020
calebcartwright pushed a commit that referenced this issue Jul 11, 2020
…#4320)

* Recognize when a block comment has been ended inside a string literal

Closes #4312

* fixup! Recognize when a block comment has been ended inside a string literal
@calebcartwright calebcartwright added the 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release label Jan 10, 2021
@karyon
Copy link
Contributor

karyon commented Oct 25, 2021

backport was done in #4796

@karyon karyon added 1x-backport:completed and removed 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release labels Oct 25, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants