Skip to content

Commit f9c159c

Browse files
committed
feat(pretty): Preserve the frontmatter
1 parent e5a4ef2 commit f9c159c

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

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