fix: Include frontmatter in -Zunpretty output

In the implementation (#140035), this was left as an open question for
the tracking issue (#136889).  My assumption is that this should be
carried over.

Thankfully, either way, `-Zunpretty` is unstable and we can always
change it even if we stabilize frontmatter.
This commit is contained in:
Ed Page 2025-07-09 15:35:52 -05:00
parent df53b3dc04
commit a11ee5614c
2 changed files with 11 additions and 1 deletions

View file

@ -120,7 +120,7 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
pos += shebang_len;
}
for token in rustc_lexer::tokenize(&text[pos..], rustc_lexer::FrontmatterAllowed::No) {
for token in rustc_lexer::tokenize(&text[pos..], rustc_lexer::FrontmatterAllowed::Yes) {
let token_text = &text[pos..pos + token.len as usize];
match token.kind {
rustc_lexer::TokenKind::Whitespace => {
@ -171,6 +171,14 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
})
}
}
rustc_lexer::TokenKind::Frontmatter { .. } => {
code_to_the_left = false;
comments.push(Comment {
style: CommentStyle::Isolated,
lines: vec![token_text.to_string()],
pos: start_bpos + BytePos(pos as u32),
});
}
_ => {
code_to_the_left = true;
}

View file

@ -1,3 +1,5 @@
---
---
//@ compile-flags: -Zunpretty=normal
//@ check-pass