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 <david@davidtw.co>
This commit is contained in:
David Wood 2020-07-12 18:22:09 +01:00
parent 346aec9b02
commit 083c2f6ceb
No known key found for this signature in database
GPG Key ID: 2592E76C87381FD9
2 changed files with 47 additions and 2 deletions

View File

@ -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 => {

View File

@ -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;
}