about summary refs log tree commit diff
path: root/compiler/rustc_lexer/src/cursor.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-07-27 13:59:30 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-08-01 08:53:04 +1000
commit99f5c79d64c268e8603c6b00c88abda7319f26e2 (patch)
tree8eb91e84571f46b4908f07f2d680b3bceb547c63 /compiler/rustc_lexer/src/cursor.rs
parente6b9fccfb12a19a928c238e0bbbd2ddec02885ed (diff)
downloadrust-99f5c79d64c268e8603c6b00c88abda7319f26e2.tar.gz
rust-99f5c79d64c268e8603c6b00c88abda7319f26e2.zip
Shrink `Token`.
From 72 bytes to 12 bytes (on x86-64).

There are two parts to this:
- Changing various source code offsets from 64-bit to 32-bit. This is
  not a problem because the rest of rustc also uses 32-bit source code
  offsets. This means `Token` is no longer `Copy` but this causes no
  problems.
- Removing the `RawStrError` from `LiteralKind`. Raw string literal
  invalidity is now indicated by a `None` value within
  `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be
  used to re-lex an invalid raw string literal to get the `RawStrError`.

There is one very small change in behaviour. Previously, if a raw string
literal matched both the `InvalidStarter` and `TooManyHashes` cases,
the latter would override the former. This has now changed, because
`raw_double_quoted_string` now uses `?` and so returns immediately upon
detecting the `InvalidStarter` case. I think this is a slight
improvement to report the earlier-detected error, and it explains the
change in the `test_too_many_hashes` test.

The commit also removes a couple of comments that refer to #77629 and
say that the size of these types don't affect performance. These
comments are wrong, though the performance effect is small.
Diffstat (limited to 'compiler/rustc_lexer/src/cursor.rs')
-rw-r--r--compiler/rustc_lexer/src/cursor.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_lexer/src/cursor.rs b/compiler/rustc_lexer/src/cursor.rs
index 0ba6c56dbb5..21557a9c854 100644
--- a/compiler/rustc_lexer/src/cursor.rs
+++ b/compiler/rustc_lexer/src/cursor.rs
@@ -61,8 +61,8 @@ impl<'a> Cursor<'a> {
     }
 
     /// Returns amount of already consumed symbols.
-    pub(crate) fn len_consumed(&self) -> usize {
-        self.initial_len - self.chars.as_str().len()
+    pub(crate) fn len_consumed(&self) -> u32 {
+        (self.initial_len - self.chars.as_str().len()) as u32
     }
 
     /// Resets the number of bytes consumed to 0.