From: Julian Wollersberger <24991778+Julian-Wollersberger@users.noreply.github.com> Date: Mon, 1 Jun 2020 11:25:41 +0000 (+0200) Subject: Cleanup: Inline `struct_span_fatal()`, which is only called once, and remove an outda... X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=7be8077b3fe7565573001b602f8709467da903e7;p=rust.git Cleanup: Inline `struct_span_fatal()`, which is only called once, and remove an outdated FIXME. --- diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index f8a5db26d32..7e59f06e44a 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -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` 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();