mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-07 13:25:45 +00:00
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](d12ea39896
) was from 2011!d12ea39896/src/comp/pretty/pprust.rs (L1146-L1150)
This commit is contained in:
commit
92e90f943c
@ -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 => {
|
||||
|
34
src/test/pretty/issue-73626.rs
Normal file
34
src/test/pretty/issue-73626.rs
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user