Skip to content

Commit afc14be

Browse files
committed
feat(pretty): Preserve the frontmatter
1 parent 232a5eb commit afc14be

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+9
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
121121
pos += shebang_len;
122122
}
123123

124+
if let Some(frontmatter_len) = rustc_lexer::strip_frontmatter(&text[pos..]) {
125+
comments.push(Comment {
126+
style: CommentStyle::Isolated,
127+
lines: vec![text[pos..pos + frontmatter_len].to_string()],
128+
pos: start_bpos + BytePos(pos as u32),
129+
});
130+
pos += frontmatter_len;
131+
}
132+
124133
for token in rustc_lexer::tokenize(&text[pos..]) {
125134
let token_text = &text[pos..pos + token.len as usize];
126135
match token.kind {

Diff for: tests/ui/unpretty/frontmatter.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
---
2+
---
13

24
//@ compile-flags: -Zunpretty=normal
35
//@ check-pass

0 commit comments

Comments
 (0)