Skip to content

Commit 083c2f6

Browse files
committed
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 <[email protected]>
1 parent 346aec9 commit 083c2f6

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/librustc_ast_pretty/pprust.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
450450
fn print_comment(&mut self, cmnt: &comments::Comment) {
451451
match cmnt.style {
452452
comments::Mixed => {
453-
assert_eq!(cmnt.lines.len(), 1);
454453
self.zerobreak();
455-
self.word(cmnt.lines[0].clone());
454+
if let Some((last, lines)) = cmnt.lines.split_last() {
455+
self.ibox(0);
456+
457+
for line in lines {
458+
self.word(line.clone());
459+
self.hardbreak()
460+
}
461+
462+
self.word(last.clone());
463+
self.space();
464+
465+
self.end();
466+
}
456467
self.zerobreak()
457468
}
458469
comments::Isolated => {

src/test/pretty/issue-73626.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
fn main(/*
2+
---
3+
*/) {
4+
let x /* this is one line */ = 3;
5+
6+
let x /*
7+
* this
8+
* is
9+
* multiple
10+
* lines
11+
*/ = 3;
12+
13+
let x = /*
14+
* this
15+
* is
16+
* multiple
17+
* lines
18+
* after
19+
* the
20+
* =
21+
*/ 3;
22+
23+
let x /*
24+
* this
25+
* is
26+
* multiple
27+
* lines
28+
* including
29+
* a
30+
31+
* blank
32+
* line
33+
*/ = 3;
34+
}

0 commit comments

Comments
 (0)