diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-07-22 11:42:36 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-08-06 22:13:11 +0300 |
| commit | 000c070b70eba07a903db82fb8505433842fe1f1 (patch) | |
| tree | 657436dd67e079ff2abeef5a34dd2578841c6ebb | |
| parent | 46f48d31fed06295a83f7695b74159ff58a0943c (diff) | |
| download | rust-000c070b70eba07a903db82fb8505433842fe1f1.tar.gz rust-000c070b70eba07a903db82fb8505433842fe1f1.zip | |
rustc_ast/comments: Modernize some enum reexports
| -rw-r--r-- | src/librustc_ast/util/comments.rs | 18 | ||||
| -rw-r--r-- | src/librustc_ast_pretty/pprust.rs | 25 |
2 files changed, 23 insertions, 20 deletions
diff --git a/src/librustc_ast/util/comments.rs b/src/librustc_ast/util/comments.rs index 543c22f4def..20d44d5a6a7 100644 --- a/src/librustc_ast/util/comments.rs +++ b/src/librustc_ast/util/comments.rs @@ -1,5 +1,3 @@ -pub use CommentStyle::*; - use crate::ast::AttrStyle; use crate::token::CommentKind; use rustc_span::source_map::SourceMap; @@ -198,7 +196,7 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme if let Some(shebang_len) = rustc_lexer::strip_shebang(text) { comments.push(Comment { - style: Isolated, + style: CommentStyle::Isolated, lines: vec![text[..shebang_len].to_string()], pos: start_bpos, }); @@ -214,7 +212,7 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme while let Some(next_newline) = &token_text[idx + 1..].find('\n') { idx = idx + 1 + next_newline; comments.push(Comment { - style: BlankLine, + style: CommentStyle::BlankLine, lines: vec![], pos: start_bpos + BytePos((pos + idx) as u32), }); @@ -228,9 +226,9 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme _ => true, }; let style = match (code_to_the_left, code_to_the_right) { - (_, true) => Mixed, - (false, false) => Isolated, - (true, false) => Trailing, + (_, true) => CommentStyle::Mixed, + (false, false) => CommentStyle::Isolated, + (true, false) => CommentStyle::Trailing, }; // 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 rustc_lexer::TokenKind::LineComment => { if line_doc_comment_style(token_text).is_none() { comments.push(Comment { - style: if code_to_the_left { Trailing } else { Isolated }, + style: if code_to_the_left { + CommentStyle::Trailing + } else { + CommentStyle::Isolated + }, lines: vec![token_text.to_string()], pos: start_bpos + BytePos(pos as u32), }) diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index 243cd24e306..9d9ca78de55 100644 --- a/src/librustc_ast_pretty/pprust.rs +++ b/src/librustc_ast_pretty/pprust.rs @@ -10,8 +10,9 @@ use rustc_ast::attr; use rustc_ast::ptr::P; use rustc_ast::token::{self, BinOpToken, CommentKind, DelimToken, Nonterminal, Token, TokenKind}; use rustc_ast::tokenstream::{TokenStream, TokenTree}; +use rustc_ast::util::classify; +use rustc_ast::util::comments::{gather_comments, Comment, CommentStyle}; use rustc_ast::util::parser::{self, AssocOp, Fixity}; -use rustc_ast::util::{classify, comments}; use rustc_span::edition::Edition; use rustc_span::source_map::{SourceMap, Spanned}; use rustc_span::symbol::{kw, sym, Ident, IdentPrinter, Symbol}; @@ -50,17 +51,17 @@ impl PpAnn for NoAnn {} pub struct Comments<'a> { sm: &'a SourceMap, - comments: Vec<comments::Comment>, + comments: Vec<Comment>, current: usize, } impl<'a> Comments<'a> { pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> { - let comments = comments::gather_comments(sm, filename, input); + let comments = gather_comments(sm, filename, input); Comments { sm, comments, current: 0 } } - pub fn next(&self) -> Option<comments::Comment> { + pub fn next(&self) -> Option<Comment> { self.comments.get(self.current).cloned() } @@ -68,9 +69,9 @@ impl<'a> Comments<'a> { &mut self, span: rustc_span::Span, next_pos: Option<BytePos>, - ) -> Option<comments::Comment> { + ) -> Option<Comment> { if let Some(cmnt) = self.next() { - if cmnt.style != comments::Trailing { + if cmnt.style != CommentStyle::Trailing { return None; } 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 } } - fn print_comment(&mut self, cmnt: &comments::Comment) { + fn print_comment(&mut self, cmnt: &Comment) { match cmnt.style { - comments::Mixed => { + CommentStyle::Mixed => { if !self.is_beginning_of_line() { self.zerobreak(); } @@ -483,7 +484,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere } self.zerobreak() } - comments::Isolated => { + CommentStyle::Isolated => { self.hardbreak_if_not_bol(); for line in &cmnt.lines { // 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 self.hardbreak(); } } - comments::Trailing => { + CommentStyle::Trailing => { if !self.is_beginning_of_line() { self.word(" "); } @@ -512,7 +513,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere self.end(); } } - comments::BlankLine => { + CommentStyle::BlankLine => { // We need to do at least one, possibly two hardbreaks. let twice = match self.last_token() { pp::Token::String(s) => ";" == s, @@ -531,7 +532,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere } } - fn next_comment(&mut self) -> Option<comments::Comment> { + fn next_comment(&mut self) -> Option<Comment> { self.comments().as_mut().and_then(|c| c.next()) } |
