about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-14 13:19:32 -0700
committerGitHub <noreply@github.com>2020-07-14 13:19:32 -0700
commit92e90f943cf6b62346074b3a17669c3a7c1637b4 (patch)
tree5e2d6ac0731853b1d29b04a41cd834560d3dabdd /src
parent7b1247c34fe40f397053344b2f98a51fcc45f2a2 (diff)
parent083c2f6ceb82b75ec04c73f2b39a414985fd9a92 (diff)
downloadrust-92e90f943cf6b62346074b3a17669c3a7c1637b4.tar.gz
rust-92e90f943cf6b62346074b3a17669c3a7c1637b4.zip
Rollup merge of #74272 - davidtwco:issue-73626-multiline-mixed-comments, r=Mark-Simulacrum
pprust: support multiline comments within lines

Fixes #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](https://github.com/rust-lang/rust/commit/d12ea3989649616437a7c1434f5c5a6438235eb7) was from 2011!
https://github.com/rust-lang/rust/blob/d12ea3989649616437a7c1434f5c5a6438235eb7/src/comp/pretty/pprust.rs#L1146-L1150
Diffstat (limited to 'src')
-rw-r--r--src/librustc_ast_pretty/pprust.rs15
-rw-r--r--src/test/pretty/issue-73626.rs34
2 files changed, 47 insertions, 2 deletions
diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs
index 2d803262f79..c33cae57872 100644
--- a/src/librustc_ast_pretty/pprust.rs
+++ b/src/librustc_ast_pretty/pprust.rs
@@ -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 => {
diff --git a/src/test/pretty/issue-73626.rs b/src/test/pretty/issue-73626.rs
new file mode 100644
index 00000000000..a002f09be3b
--- /dev/null
+++ b/src/test/pretty/issue-73626.rs
@@ -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;
+}