Skip to content

Commit

Permalink
Cleanup: Inline struct_span_fatal(), which is only called once, and…
Browse files Browse the repository at this point in the history
… remove an outdated FIXME.
  • Loading branch information
Julian-Wollersberger committed Jun 1, 2020
1 parent 5fbbfbb commit 7be8077
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/librustc_parse/lexer/mod.rs
Expand Up @@ -49,13 +49,12 @@ impl<'a> StringReader<'a> {
// 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));
Expand Down Expand Up @@ -125,10 +124,7 @@ impl<'a> StringReader<'a> {

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)
}
Expand All @@ -153,15 +149,6 @@ impl<'a> StringReader<'a> {
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,
Expand Down Expand Up @@ -380,12 +367,7 @@ impl<'a> StringReader<'a> {
}
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 {
Expand Down Expand Up @@ -475,8 +457,7 @@ impl<'a> StringReader<'a> {
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();
Expand Down

0 comments on commit 7be8077

Please sign in to comment.