]> git.lizzy.rs Git - rust.git/commitdiff
Cleanup: Inline `struct_span_fatal()`, which is only called once, and remove an outda...
authorJulian Wollersberger <24991778+Julian-Wollersberger@users.noreply.github.com>
Mon, 1 Jun 2020 11:25:41 +0000 (13:25 +0200)
committerJulian Wollersberger <24991778+Julian-Wollersberger@users.noreply.github.com>
Mon, 1 Jun 2020 20:01:30 +0000 (22:01 +0200)
src/librustc_parse/lexer/mod.rs

index f8a5db26d3231e05764e202b666711d313b3fd93..7e59f06e44ae3ecd43fb3530238210233add403a 100644 (file)
@@ -49,13 +49,12 @@ pub fn new(
         // Make sure external source is loaded first, before accessing it.
         // While this can't show up during normal parsing, `retokenize` may
         // be called with a source file from an external crate.
-        sess.source_map().ensure_source_file_source_present(source_file.clone());
+        sess.source_map().ensure_source_file_source_present(Lrc::clone(&source_file));
 
-        // FIXME(eddyb) use `Lrc<str>` or similar to avoid cloning the `String`.
         let src = if let Some(src) = &source_file.src {
-            src.clone()
+            Lrc::clone(&src)
         } else if let Some(src) = source_file.external_src.borrow().get_source() {
-            src.clone()
+            Lrc::clone(&src)
         } else {
             sess.span_diagnostic
                 .bug(&format!("cannot lex `source_file` without source: {}", source_file.name));
@@ -125,10 +124,7 @@ pub fn next_token(&mut self) -> Token {
 
         debug!("try_next_token: {:?}({:?})", token.kind, self.str_from(start));
 
-        // This could use `?`, but that makes code significantly (10-20%) slower.
-        // https://github.com/rust-lang/rust/issues/37939
         let kind = self.cook_lexer_token(token.kind, start);
-
         let span = self.mk_sp(start, self.pos);
         Token::new(kind, span)
     }
@@ -153,15 +149,6 @@ fn err_span_(&self, from_pos: BytePos, to_pos: BytePos, m: &str) {
         self.err_span(self.mk_sp(from_pos, to_pos), m)
     }
 
-    fn struct_span_fatal(
-        &self,
-        from_pos: BytePos,
-        to_pos: BytePos,
-        m: &str,
-    ) -> DiagnosticBuilder<'a> {
-        self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), m)
-    }
-
     fn struct_fatal_span_char(
         &self,
         from_pos: BytePos,
@@ -380,12 +367,7 @@ fn cook_lexer_literal(
             }
             rustc_lexer::LiteralKind::Float { base, empty_exponent } => {
                 if empty_exponent {
-                    let mut err = self.struct_span_fatal(
-                        start,
-                        self.pos,
-                        "expected at least one digit in exponent",
-                    );
-                    err.emit();
+                    self.err_span_(start, self.pos, "expected at least one digit in exponent");
                 }
 
                 match base {
@@ -475,8 +457,7 @@ fn report_non_started_raw_string(&self, start: BytePos, bad_char: char) -> ! {
         self.struct_fatal_span_char(
             start,
             self.pos,
-            "found invalid character; only `#` is allowed \
-                 in raw string delimitation",
+            "found invalid character; only `#` is allowed in raw string delimitation",
             bad_char,
         )
         .emit();