Skip to content

Commit ed5aad9

Browse files
committed
feat(pretty): Preserve the frontmatter
1 parent aded90a commit ed5aad9

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
@@ -123,6 +123,15 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
123123
pos += shebang_len;
124124
}
125125

126+
if let Some(frontmatter_len) = rustc_lexer::strip_frontmatter(&text[pos..]) {
127+
comments.push(Comment {
128+
style: CommentStyle::Isolated,
129+
lines: vec![text[pos..frontmatter_len].to_string()],
130+
pos: start_bpos + BytePos(pos as u32),
131+
});
132+
pos += frontmatter_len;
133+
}
134+
126135
for token in rustc_lexer::tokenize(&text[pos..]) {
127136
let token_text = &text[pos..pos + token.len as usize];
128137
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)