Skip to content

Commit

Permalink
Rollup merge of rust-lang#74272 - davidtwco:issue-73626-multiline-mix…
Browse files Browse the repository at this point in the history
…ed-comments, r=Mark-Simulacrum

pprust: support multiline comments within lines

Fixes rust-lang#73626.

This PR adds support to `rustc_ast_pretty` for multiline comments that start and end within a line of source code.

Fun fact: [the commit which added this assert](rust-lang@d12ea39) was from 2011!
https://github.com/rust-lang/rust/blob/d12ea3989649616437a7c1434f5c5a6438235eb7/src/comp/pretty/pprust.rs#L1146-L1150
  • Loading branch information
Manishearth committed Jul 14, 2020
2 parents 9f4933d + 083c2f6 commit 37b2615
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn print_comment(&mut self, cmnt: &comments::Comment) {
match cmnt.style {
comments::Mixed => {
assert_eq!(cmnt.lines.len(), 1);
self.zerobreak();
self.word(cmnt.lines[0].clone());
if let Some((last, lines)) = cmnt.lines.split_last() {
self.ibox(0);

for line in lines {
self.word(line.clone());
self.hardbreak()
}

self.word(last.clone());
self.space();

self.end();
}
self.zerobreak()
}
comments::Isolated => {
Expand Down
34 changes: 34 additions & 0 deletions src/test/pretty/issue-73626.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
fn main(/*
---
*/) {
let x /* this is one line */ = 3;

let x /*
* this
* is
* multiple
* lines
*/ = 3;

let x = /*
* this
* is
* multiple
* lines
* after
* the
* =
*/ 3;

let x /*
* this
* is
* multiple
* lines
* including
* a
* blank
* line
*/ = 3;
}

0 comments on commit 37b2615

Please sign in to comment.