From 083c2f6ceb82b75ec04c73f2b39a414985fd9a92 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 12 Jul 2020 18:22:09 +0100 Subject: [PATCH] pprust: support multiline comments within lines This commit adds support to rustc_ast_pretty for multiline comments that start and end within a line of source code. Signed-off-by: David Wood --- src/librustc_ast_pretty/pprust.rs | 15 ++++++++++++-- src/test/pretty/issue-73626.rs | 34 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/test/pretty/issue-73626.rs diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index 2d803262f79e1..c33cae57872ac 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 + 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 0000000000000..a002f09be3b4e --- /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; +}