Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup error handlers: round 5 #119538

Merged
merged 10 commits into from
Jan 5, 2024
Prev Previous commit
Next Next commit
Inline and remove StringReader::struct_fatal_span_char.
It has a single call site.
  • Loading branch information
nnethercote committed Jan 4, 2024
commit 8e6bca63f943a061264aec986446fac67c59c262
33 changes: 11 additions & 22 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use rustc_ast::ast::{self, AttrStyle};
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, DiagCtxt, Diagnostic, DiagnosticBuilder, FatalAbort, StashKey,
};
use rustc_errors::{error_code, Applicability, DiagCtxt, Diagnostic, StashKey};
use rustc_lexer::unescape::{self, EscapeError, Mode};
use rustc_lexer::{Base, DocStyle, RawStrError};
use rustc_lexer::{Cursor, LiteralKind};
Expand Down Expand Up @@ -344,18 +342,6 @@ impl<'a> StringReader<'a> {
token::Ident(sym, false)
}

fn struct_fatal_span_char(
&self,
from_pos: BytePos,
to_pos: BytePos,
m: &str,
c: char,
) -> DiagnosticBuilder<'a, FatalAbort> {
self.sess
.dcx
.struct_span_fatal(self.mk_sp(from_pos, to_pos), format!("{}: {}", m, escaped_char(c)))
}

/// Detect usages of Unicode codepoints changing the direction of the text on screen and loudly
/// complain about it.
fn lint_unicode_text_flow(&self, start: BytePos) {
Expand Down Expand Up @@ -568,13 +554,16 @@ impl<'a> StringReader<'a> {
}

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",
bad_char,
)
.emit()
self.sess
.dcx
.struct_span_fatal(
self.mk_sp(start, self.pos),
format!(
"found invalid character; only `#` is allowed in raw string delimitation: {}",
escaped_char(bad_char)
),
)
.emit()
}

fn report_unterminated_raw_string(
Expand Down