Skip to content

Commit 000c070

Browse files
committed
rustc_ast/comments: Modernize some enum reexports
1 parent 46f48d3 commit 000c070

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/librustc_ast/util/comments.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pub use CommentStyle::*;
2-
31
use crate::ast::AttrStyle;
42
use crate::token::CommentKind;
53
use rustc_span::source_map::SourceMap;
@@ -198,7 +196,7 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
198196

199197
if let Some(shebang_len) = rustc_lexer::strip_shebang(text) {
200198
comments.push(Comment {
201-
style: Isolated,
199+
style: CommentStyle::Isolated,
202200
lines: vec![text[..shebang_len].to_string()],
203201
pos: start_bpos,
204202
});
@@ -214,7 +212,7 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
214212
while let Some(next_newline) = &token_text[idx + 1..].find('\n') {
215213
idx = idx + 1 + next_newline;
216214
comments.push(Comment {
217-
style: BlankLine,
215+
style: CommentStyle::BlankLine,
218216
lines: vec![],
219217
pos: start_bpos + BytePos((pos + idx) as u32),
220218
});
@@ -228,9 +226,9 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
228226
_ => true,
229227
};
230228
let style = match (code_to_the_left, code_to_the_right) {
231-
(_, true) => Mixed,
232-
(false, false) => Isolated,
233-
(true, false) => Trailing,
229+
(_, true) => CommentStyle::Mixed,
230+
(false, false) => CommentStyle::Isolated,
231+
(true, false) => CommentStyle::Trailing,
234232
};
235233

236234
// Count the number of chars since the start of the line by rescanning.
@@ -246,7 +244,11 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
246244
rustc_lexer::TokenKind::LineComment => {
247245
if line_doc_comment_style(token_text).is_none() {
248246
comments.push(Comment {
249-
style: if code_to_the_left { Trailing } else { Isolated },
247+
style: if code_to_the_left {
248+
CommentStyle::Trailing
249+
} else {
250+
CommentStyle::Isolated
251+
},
250252
lines: vec![token_text.to_string()],
251253
pos: start_bpos + BytePos(pos as u32),
252254
})

src/librustc_ast_pretty/pprust.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use rustc_ast::attr;
1010
use rustc_ast::ptr::P;
1111
use rustc_ast::token::{self, BinOpToken, CommentKind, DelimToken, Nonterminal, Token, TokenKind};
1212
use rustc_ast::tokenstream::{TokenStream, TokenTree};
13+
use rustc_ast::util::classify;
14+
use rustc_ast::util::comments::{gather_comments, Comment, CommentStyle};
1315
use rustc_ast::util::parser::{self, AssocOp, Fixity};
14-
use rustc_ast::util::{classify, comments};
1516
use rustc_span::edition::Edition;
1617
use rustc_span::source_map::{SourceMap, Spanned};
1718
use rustc_span::symbol::{kw, sym, Ident, IdentPrinter, Symbol};
@@ -50,27 +51,27 @@ impl PpAnn for NoAnn {}
5051

5152
pub struct Comments<'a> {
5253
sm: &'a SourceMap,
53-
comments: Vec<comments::Comment>,
54+
comments: Vec<Comment>,
5455
current: usize,
5556
}
5657

5758
impl<'a> Comments<'a> {
5859
pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
59-
let comments = comments::gather_comments(sm, filename, input);
60+
let comments = gather_comments(sm, filename, input);
6061
Comments { sm, comments, current: 0 }
6162
}
6263

63-
pub fn next(&self) -> Option<comments::Comment> {
64+
pub fn next(&self) -> Option<Comment> {
6465
self.comments.get(self.current).cloned()
6566
}
6667

6768
pub fn trailing_comment(
6869
&mut self,
6970
span: rustc_span::Span,
7071
next_pos: Option<BytePos>,
71-
) -> Option<comments::Comment> {
72+
) -> Option<Comment> {
7273
if let Some(cmnt) = self.next() {
73-
if cmnt.style != comments::Trailing {
74+
if cmnt.style != CommentStyle::Trailing {
7475
return None;
7576
}
7677
let span_line = self.sm.lookup_char_pos(span.hi());
@@ -462,9 +463,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
462463
}
463464
}
464465

465-
fn print_comment(&mut self, cmnt: &comments::Comment) {
466+
fn print_comment(&mut self, cmnt: &Comment) {
466467
match cmnt.style {
467-
comments::Mixed => {
468+
CommentStyle::Mixed => {
468469
if !self.is_beginning_of_line() {
469470
self.zerobreak();
470471
}
@@ -483,7 +484,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
483484
}
484485
self.zerobreak()
485486
}
486-
comments::Isolated => {
487+
CommentStyle::Isolated => {
487488
self.hardbreak_if_not_bol();
488489
for line in &cmnt.lines {
489490
// Don't print empty lines because they will end up as trailing
@@ -494,7 +495,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
494495
self.hardbreak();
495496
}
496497
}
497-
comments::Trailing => {
498+
CommentStyle::Trailing => {
498499
if !self.is_beginning_of_line() {
499500
self.word(" ");
500501
}
@@ -512,7 +513,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
512513
self.end();
513514
}
514515
}
515-
comments::BlankLine => {
516+
CommentStyle::BlankLine => {
516517
// We need to do at least one, possibly two hardbreaks.
517518
let twice = match self.last_token() {
518519
pp::Token::String(s) => ";" == s,
@@ -531,7 +532,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
531532
}
532533
}
533534

534-
fn next_comment(&mut self) -> Option<comments::Comment> {
535+
fn next_comment(&mut self) -> Option<Comment> {
535536
self.comments().as_mut().and_then(|c| c.next())
536537
}
537538

0 commit comments

Comments
 (0)