1
Fork 0

Remove all eight DiagnosticBuilder::*_with_code methods.

These all have relatively low use, and can be perfectly emulated with
a simpler construction method combined with `code` or `code_mv`.
This commit is contained in:
Nicholas Nethercote 2024-01-03 21:50:36 +11:00
parent bd4e623485
commit 6682f243dc
14 changed files with 84 additions and 180 deletions

View file

@ -395,51 +395,58 @@ impl<'a> StringReader<'a> {
match kind {
rustc_lexer::LiteralKind::Char { terminated } => {
if !terminated {
self.dcx().span_fatal_with_code(
self.mk_sp(start, end),
"unterminated character literal",
error_code!(E0762),
)
self.dcx()
.struct_span_fatal(self.mk_sp(start, end), "unterminated character literal")
.code_mv(error_code!(E0762))
.emit()
}
self.cook_quoted(token::Char, Mode::Char, start, end, 1, 1) // ' '
}
rustc_lexer::LiteralKind::Byte { terminated } => {
if !terminated {
self.dcx().span_fatal_with_code(
self.mk_sp(start + BytePos(1), end),
"unterminated byte constant",
error_code!(E0763),
)
self.dcx()
.struct_span_fatal(
self.mk_sp(start + BytePos(1), end),
"unterminated byte constant",
)
.code_mv(error_code!(E0763))
.emit()
}
self.cook_quoted(token::Byte, Mode::Byte, start, end, 2, 1) // b' '
}
rustc_lexer::LiteralKind::Str { terminated } => {
if !terminated {
self.dcx().span_fatal_with_code(
self.mk_sp(start, end),
"unterminated double quote string",
error_code!(E0765),
)
self.dcx()
.struct_span_fatal(
self.mk_sp(start, end),
"unterminated double quote string",
)
.code_mv(error_code!(E0765))
.emit()
}
self.cook_quoted(token::Str, Mode::Str, start, end, 1, 1) // " "
}
rustc_lexer::LiteralKind::ByteStr { terminated } => {
if !terminated {
self.dcx().span_fatal_with_code(
self.mk_sp(start + BytePos(1), end),
"unterminated double quote byte string",
error_code!(E0766),
)
self.dcx()
.struct_span_fatal(
self.mk_sp(start + BytePos(1), end),
"unterminated double quote byte string",
)
.code_mv(error_code!(E0766))
.emit()
}
self.cook_quoted(token::ByteStr, Mode::ByteStr, start, end, 2, 1) // b" "
}
rustc_lexer::LiteralKind::CStr { terminated } => {
if !terminated {
self.dcx().span_fatal_with_code(
self.mk_sp(start + BytePos(1), end),
"unterminated C string",
error_code!(E0767),
)
self.dcx()
.struct_span_fatal(
self.mk_sp(start + BytePos(1), end),
"unterminated C string",
)
.code_mv(error_code!(E0767))
.emit()
}
self.cook_c_string(token::CStr, Mode::CStr, start, end, 2, 1) // c" "
}
@ -573,12 +580,9 @@ impl<'a> StringReader<'a> {
possible_offset: Option<u32>,
found_terminators: u32,
) -> ! {
let mut err = self.dcx().struct_span_fatal_with_code(
self.mk_sp(start, start),
"unterminated raw string",
error_code!(E0748),
);
let mut err =
self.dcx().struct_span_fatal(self.mk_sp(start, start), "unterminated raw string");
err.code(error_code!(E0748));
err.span_label(self.mk_sp(start, start), "unterminated raw string");
if n_hashes > 0 {
@ -609,11 +613,8 @@ impl<'a> StringReader<'a> {
None => "unterminated block comment",
};
let last_bpos = self.pos;
let mut err = self.dcx().struct_span_fatal_with_code(
self.mk_sp(start, last_bpos),
msg,
error_code!(E0758),
);
let mut err = self.dcx().struct_span_fatal(self.mk_sp(start, last_bpos), msg);
err.code(error_code!(E0758));
let mut nested_block_comment_open_idxs = vec![];
let mut last_nested_block_comment_idxs = None;
let mut content_chars = self.str_from(start).char_indices().peekable();

View file

@ -55,11 +55,10 @@ impl<'a> Parser<'a> {
} else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind {
if attr_style != ast::AttrStyle::Outer {
let span = self.token.span;
let mut err = self.dcx().struct_span_err_with_code(
span,
fluent::parse_inner_doc_comment_not_permitted,
error_code!(E0753),
);
let mut err = self
.dcx()
.struct_span_err(span, fluent::parse_inner_doc_comment_not_permitted);
err.code(error_code!(E0753));
if let Some(replacement_span) = self.annotate_following_item_if_applicable(
&mut err,
span,