about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-09-28 10:28:36 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-09-28 11:15:23 +1000
commitd0a26acb2ae2d000e516eca92ae8feb08d1f6ea0 (patch)
treeeade9bfbafbc49a3c083da51d9ae0a90010dcf4b
parent7f7e2165b1f1a271c6708f2a54c940bdaa254eb2 (diff)
downloadrust-d0a26acb2ae2d000e516eca92ae8feb08d1f6ea0.tar.gz
rust-d0a26acb2ae2d000e516eca92ae8feb08d1f6ea0.zip
Address review comments.
-rw-r--r--compiler/rustc_lexer/src/lib.rs6
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs2
-rw-r--r--compiler/rustc_parse/src/lexer/tokentrees.rs14
-rw-r--r--src/librustdoc/html/highlight.rs2
4 files changed, 13 insertions, 11 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs
index 18ebed7c70e..c71e6ffe34d 100644
--- a/compiler/rustc_lexer/src/lib.rs
+++ b/compiler/rustc_lexer/src/lib.rs
@@ -23,15 +23,17 @@
 // We want to be able to build this crate with a stable compiler, so no
 // `#![feature]` attributes should be added.
 
-pub mod cursor;
+mod cursor;
 pub mod unescape;
 
 #[cfg(test)]
 mod tests;
 
+pub use crate::cursor::Cursor;
+
 use self::LiteralKind::*;
 use self::TokenKind::*;
-use crate::cursor::{Cursor, EOF_CHAR};
+use crate::cursor::EOF_CHAR;
 use std::convert::TryFrom;
 
 /// Parsed token.
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index 151e80e2b3e..bcd078a8967 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -4,8 +4,8 @@ use rustc_ast::token::{self, CommentKind, Delimiter, Token, TokenKind};
 use rustc_ast::tokenstream::TokenStream;
 use rustc_ast::util::unicode::contains_text_flow_control_chars;
 use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
-use rustc_lexer::cursor::Cursor;
 use rustc_lexer::unescape::{self, Mode};
+use rustc_lexer::Cursor;
 use rustc_lexer::{Base, DocStyle, RawStrError};
 use rustc_session::lint::builtin::{
     RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX, TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs
index 6f6ab16cb59..364753154db 100644
--- a/compiler/rustc_parse/src/lexer/tokentrees.rs
+++ b/compiler/rustc_parse/src/lexer/tokentrees.rs
@@ -53,7 +53,7 @@ impl<'a> TokenTreesReader<'a> {
                 token::OpenDelim(delim) => buf.push(self.parse_token_tree_open_delim(delim)),
                 token::CloseDelim(delim) => return Err(self.close_delim_err(delim)),
                 token::Eof => return Ok(buf.into_token_stream()),
-                _ => buf.push(self.parse_token_tree_other()),
+                _ => buf.push(self.parse_token_tree_non_delim_non_eof()),
             }
         }
     }
@@ -66,11 +66,10 @@ impl<'a> TokenTreesReader<'a> {
                 token::OpenDelim(delim) => buf.push(self.parse_token_tree_open_delim(delim)),
                 token::CloseDelim(..) => return buf.into_token_stream(),
                 token::Eof => {
-                    let mut err = self.eof_err();
-                    err.emit();
+                    self.eof_err().emit();
                     return buf.into_token_stream();
                 }
-                _ => buf.push(self.parse_token_tree_other()),
+                _ => buf.push(self.parse_token_tree_non_delim_non_eof()),
             }
         }
     }
@@ -245,9 +244,10 @@ impl<'a> TokenTreesReader<'a> {
     }
 
     #[inline]
-    fn parse_token_tree_other(&mut self) -> TokenTree {
-        // `spacing` for the returned token is determined by the next token:
-        // its kind and its `preceded_by_whitespace` status.
+    fn parse_token_tree_non_delim_non_eof(&mut self) -> TokenTree {
+        // `this_spacing` for the returned token refers to whether the token is
+        // immediately followed by another op token. It is determined by the
+        // next token: its kind and its `preceded_by_whitespace` status.
         let (next_tok, is_next_tok_preceded_by_whitespace) = self.string_reader.next_token();
         let this_spacing = if is_next_tok_preceded_by_whitespace || !next_tok.is_op() {
             Spacing::Alone
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index ea65a6334c9..78b98431b19 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -13,7 +13,7 @@ use std::collections::VecDeque;
 use std::fmt::{Display, Write};
 
 use rustc_data_structures::fx::FxHashMap;
-use rustc_lexer::cursor::Cursor;
+use rustc_lexer::Cursor;
 use rustc_lexer::{LiteralKind, TokenKind};
 use rustc_span::edition::Edition;
 use rustc_span::symbol::Symbol;