1
Fork 0

Use chaining in DiagnosticBuilder construction.

To avoid the use of a mutable local variable, and because it reads more
nicely.
This commit is contained in:
Nicholas Nethercote 2024-01-03 16:00:29 +11:00
parent b1b9278851
commit 589591efde
22 changed files with 223 additions and 369 deletions

View file

@ -54,13 +54,12 @@ pub(crate) struct UnknownMetaItem<'a> {
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>(); let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item); DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item)
diag.span(self.span); .span_mv(self.span)
diag.code(error_code!(E0541)); .code_mv(error_code!(E0541))
diag.arg("item", self.item); .arg_mv("item", self.item)
diag.arg("expected", expected.join(", ")); .arg_mv("expected", expected.join(", "))
diag.span_label(self.span, fluent::attr_label); .span_label_mv(self.span, fluent::attr_label)
diag
} }
} }

View file

@ -31,17 +31,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span, borrow_span: Span,
borrow_desc: &str, borrow_desc: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0503, E0503,
"cannot use {} because it was mutably borrowed", "cannot use {} because it was mutably borrowed",
desc, desc,
); )
.span_label_mv(borrow_span, format!("{borrow_desc} is borrowed here"))
err.span_label(borrow_span, format!("{borrow_desc} is borrowed here")); .span_label_mv(span, format!("use of borrowed {borrow_desc}"))
err.span_label(span, format!("use of borrowed {borrow_desc}"));
err
} }
pub(crate) fn cannot_mutably_borrow_multiply( pub(crate) fn cannot_mutably_borrow_multiply(
@ -238,17 +236,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span, borrow_span: Span,
desc: &str, desc: &str,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0506, E0506,
"cannot assign to {} because it is borrowed", "cannot assign to {} because it is borrowed",
desc, desc,
); )
.span_label_mv(borrow_span, format!("{desc} is borrowed here"))
err.span_label(borrow_span, format!("{desc} is borrowed here")); .span_label_mv(span, format!("{desc} is assigned to here but it was already borrowed"))
err.span_label(span, format!("{desc} is assigned to here but it was already borrowed"));
err
} }
pub(crate) fn cannot_reassign_immutable( pub(crate) fn cannot_reassign_immutable(
@ -287,16 +283,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
(&ty::Slice(_), _) => "slice", (&ty::Slice(_), _) => "slice",
_ => span_bug!(move_from_span, "this path should not cause illegal move"), _ => span_bug!(move_from_span, "this path should not cause illegal move"),
}; };
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
move_from_span, move_from_span,
E0508, E0508,
"cannot move out of type `{}`, a non-copy {}", "cannot move out of type `{}`, a non-copy {}",
ty, ty,
type_name, type_name,
); )
err.span_label(move_from_span, "cannot move out of here"); .span_label_mv(move_from_span, "cannot move out of here")
err
} }
pub(crate) fn cannot_move_out_of_interior_of_drop( pub(crate) fn cannot_move_out_of_interior_of_drop(
@ -304,15 +299,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span, move_from_span: Span,
container_ty: Ty<'_>, container_ty: Ty<'_>,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
move_from_span, move_from_span,
E0509, E0509,
"cannot move out of type `{}`, which implements the `Drop` trait", "cannot move out of type `{}`, which implements the `Drop` trait",
container_ty, container_ty,
); )
err.span_label(move_from_span, "cannot move out of here"); .span_label_mv(move_from_span, "cannot move out of here")
err
} }
pub(crate) fn cannot_act_on_moved_value( pub(crate) fn cannot_act_on_moved_value(
@ -352,7 +346,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_section: &str, immutable_section: &str,
action: &str, action: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
mutate_span, mutate_span,
E0510, E0510,
@ -360,10 +354,9 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
action, action,
immutable_place, immutable_place,
immutable_section, immutable_section,
); )
err.span_label(mutate_span, format!("cannot {action}")); .span_label_mv(mutate_span, format!("cannot {action}"))
err.span_label(immutable_span, format!("value is immutable in {immutable_section}")); .span_label_mv(immutable_span, format!("value is immutable in {immutable_section}"))
err
} }
pub(crate) fn cannot_borrow_across_coroutine_yield( pub(crate) fn cannot_borrow_across_coroutine_yield(
@ -372,14 +365,13 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
yield_span: Span, yield_span: Span,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind; let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0626, E0626,
"borrow may still be in use when {coroutine_kind:#} yields", "borrow may still be in use when {coroutine_kind:#} yields",
); )
err.span_label(yield_span, "possible yield occurs here"); .span_label_mv(yield_span, "possible yield occurs here")
err
} }
pub(crate) fn cannot_borrow_across_destructor( pub(crate) fn cannot_borrow_across_destructor(
@ -409,7 +401,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
reference_desc: &str, reference_desc: &str,
path_desc: &str, path_desc: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0515, E0515,
@ -417,14 +409,11 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
RETURN = return_kind, RETURN = return_kind,
REFERENCE = reference_desc, REFERENCE = reference_desc,
LOCAL = path_desc, LOCAL = path_desc,
); )
.span_label_mv(
err.span_label(
span, span,
format!("{return_kind}s a {reference_desc} data owned by the current function"), format!("{return_kind}s a {reference_desc} data owned by the current function"),
); )
err
} }
pub(crate) fn cannot_capture_in_long_lived_closure( pub(crate) fn cannot_capture_in_long_lived_closure(
@ -435,16 +424,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
capture_span: Span, capture_span: Span,
scope: &str, scope: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
closure_span, closure_span,
E0373, E0373,
"{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \ "{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
which is owned by the current {scope}", which is owned by the current {scope}",
); )
err.span_label(capture_span, format!("{borrowed_path} is borrowed here")) .span_label_mv(capture_span, format!("{borrowed_path} is borrowed here"))
.span_label(closure_span, format!("may outlive borrowed value {borrowed_path}")); .span_label_mv(closure_span, format!("may outlive borrowed value {borrowed_path}"))
err
} }
pub(crate) fn thread_local_value_does_not_live_long_enough( pub(crate) fn thread_local_value_does_not_live_long_enough(

View file

@ -2218,15 +2218,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
drop_span, borrow_span drop_span, borrow_span
); );
let mut err = self.thread_local_value_does_not_live_long_enough(borrow_span); self.thread_local_value_does_not_live_long_enough(borrow_span)
.span_label_mv(
err.span_label(
borrow_span, borrow_span,
"thread-local variables cannot be borrowed beyond the end of the function", "thread-local variables cannot be borrowed beyond the end of the function",
); )
err.span_label(drop_span, "end of enclosing function is here"); .span_label_mv(drop_span, "end of enclosing function is here")
err
} }
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]

View file

@ -329,15 +329,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let PlaceRef { local, projection: [] } = deref_base { if let PlaceRef { local, projection: [] } = deref_base {
let decl = &self.body.local_decls[local]; let decl = &self.body.local_decls[local];
if decl.is_ref_for_guard() { if decl.is_ref_for_guard() {
let mut err = self.cannot_move_out_of( return self
.cannot_move_out_of(
span, span,
&format!("`{}` in pattern guard", self.local_names[local].unwrap()), &format!("`{}` in pattern guard", self.local_names[local].unwrap()),
); )
err.note( .note_mv(
"variables bound in patterns cannot be moved from \ "variables bound in patterns cannot be moved from \
until after the end of the pattern guard", until after the end of the pattern guard",
); );
return err;
} else if decl.is_ref_to_static() { } else if decl.is_ref_to_static() {
return self.report_cannot_move_from_static(move_place, span); return self.report_cannot_move_from_static(move_place, span);
} }
@ -381,15 +381,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
closure_kind_ty, closure_kind, place_description, closure_kind_ty, closure_kind, place_description,
); );
let mut diag = self.cannot_move_out_of(span, &place_description); self.cannot_move_out_of(span, &place_description)
.span_label_mv(upvar_span, "captured outer variable")
diag.span_label(upvar_span, "captured outer variable"); .span_label_mv(
diag.span_label(
self.infcx.tcx.def_span(def_id), self.infcx.tcx.def_span(def_id),
format!("captured by this `{closure_kind}` closure"), format!("captured by this `{closure_kind}` closure"),
); )
diag
} }
_ => { _ => {
let source = self.borrowed_content_source(deref_base); let source = self.borrowed_content_source(deref_base);

View file

@ -803,24 +803,23 @@ pub(crate) struct AsmClobberNoReg {
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
let mut diag = DiagnosticBuilder::new(
dcx,
level,
crate::fluent_generated::builtin_macros_asm_clobber_no_reg,
);
diag.span(self.spans.clone());
// eager translation as `span_labels` takes `AsRef<str>` // eager translation as `span_labels` takes `AsRef<str>`
let lbl1 = dcx.eagerly_translate_to_string( let lbl1 = dcx.eagerly_translate_to_string(
crate::fluent_generated::builtin_macros_asm_clobber_abi, crate::fluent_generated::builtin_macros_asm_clobber_abi,
[].into_iter(), [].into_iter(),
); );
diag.span_labels(self.clobbers, &lbl1);
let lbl2 = dcx.eagerly_translate_to_string( let lbl2 = dcx.eagerly_translate_to_string(
crate::fluent_generated::builtin_macros_asm_clobber_outputs, crate::fluent_generated::builtin_macros_asm_clobber_outputs,
[].into_iter(), [].into_iter(),
); );
diag.span_labels(self.spans, &lbl2); DiagnosticBuilder::new(
diag dcx,
level,
crate::fluent_generated::builtin_macros_asm_clobber_no_reg,
)
.span_mv(self.spans.clone())
.span_labels_mv(self.clobbers, &lbl1)
.span_labels_mv(self.spans, &lbl2)
} }
} }

View file

@ -105,10 +105,8 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_
let (message, _) = diag.messages().first().expect("`LlvmError` with no message"); let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args()); let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config); .arg_mv("error", message)
diag.arg("error", message);
diag
} }
} }
@ -204,10 +202,10 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err, PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err,
ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err, ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
}; };
let mut diag = self.0.into_diagnostic(dcx, level); self.0
diag.primary_message(msg_with_llvm_err); .into_diagnostic(dcx, level)
diag.arg("llvm_err", self.1); .primary_message_mv(msg_with_llvm_err)
diag .arg_mv("llvm_err", self.1)
} }
} }

View file

@ -212,192 +212,124 @@ pub struct ThorinErrorWrapper(pub thorin::Error);
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper { impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
let build = |msg| DiagnosticBuilder::new(dcx, level, msg); let build = |msg| DiagnosticBuilder::new(dcx, level, msg);
let mut diag;
match self.0 { match self.0 {
thorin::Error::ReadInput(_) => { thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure),
diag = build(fluent::codegen_ssa_thorin_read_input_failure);
diag
}
thorin::Error::ParseFileKind(_) => { thorin::Error::ParseFileKind(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_input_file_kind); build(fluent::codegen_ssa_thorin_parse_input_file_kind)
diag
} }
thorin::Error::ParseObjectFile(_) => { thorin::Error::ParseObjectFile(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_input_object_file); build(fluent::codegen_ssa_thorin_parse_input_object_file)
diag
} }
thorin::Error::ParseArchiveFile(_) => { thorin::Error::ParseArchiveFile(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_input_archive_file); build(fluent::codegen_ssa_thorin_parse_input_archive_file)
diag
} }
thorin::Error::ParseArchiveMember(_) => { thorin::Error::ParseArchiveMember(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_archive_member); build(fluent::codegen_ssa_thorin_parse_archive_member)
diag
}
thorin::Error::InvalidInputKind => {
diag = build(fluent::codegen_ssa_thorin_invalid_input_kind);
diag
}
thorin::Error::DecompressData(_) => {
diag = build(fluent::codegen_ssa_thorin_decompress_data);
diag
} }
thorin::Error::InvalidInputKind => build(fluent::codegen_ssa_thorin_invalid_input_kind),
thorin::Error::DecompressData(_) => build(fluent::codegen_ssa_thorin_decompress_data),
thorin::Error::NamelessSection(_, offset) => { thorin::Error::NamelessSection(_, offset) => {
diag = build(fluent::codegen_ssa_thorin_section_without_name); build(fluent::codegen_ssa_thorin_section_without_name)
diag.arg("offset", format!("0x{offset:08x}")); .arg_mv("offset", format!("0x{offset:08x}"))
diag
} }
thorin::Error::RelocationWithInvalidSymbol(section, offset) => { thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
diag = build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol); build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol)
diag.arg("section", section); .arg_mv("section", section)
diag.arg("offset", format!("0x{offset:08x}")); .arg_mv("offset", format!("0x{offset:08x}"))
diag
} }
thorin::Error::MultipleRelocations(section, offset) => { thorin::Error::MultipleRelocations(section, offset) => {
diag = build(fluent::codegen_ssa_thorin_multiple_relocations); build(fluent::codegen_ssa_thorin_multiple_relocations)
diag.arg("section", section); .arg_mv("section", section)
diag.arg("offset", format!("0x{offset:08x}")); .arg_mv("offset", format!("0x{offset:08x}"))
diag
} }
thorin::Error::UnsupportedRelocation(section, offset) => { thorin::Error::UnsupportedRelocation(section, offset) => {
diag = build(fluent::codegen_ssa_thorin_unsupported_relocation); build(fluent::codegen_ssa_thorin_unsupported_relocation)
diag.arg("section", section); .arg_mv("section", section)
diag.arg("offset", format!("0x{offset:08x}")); .arg_mv("offset", format!("0x{offset:08x}"))
diag
}
thorin::Error::MissingDwoName(id) => {
diag = build(fluent::codegen_ssa_thorin_missing_dwo_name);
diag.arg("id", format!("0x{id:08x}"));
diag
} }
thorin::Error::MissingDwoName(id) => build(fluent::codegen_ssa_thorin_missing_dwo_name)
.arg_mv("id", format!("0x{id:08x}")),
thorin::Error::NoCompilationUnits => { thorin::Error::NoCompilationUnits => {
diag = build(fluent::codegen_ssa_thorin_no_compilation_units); build(fluent::codegen_ssa_thorin_no_compilation_units)
diag
}
thorin::Error::NoDie => {
diag = build(fluent::codegen_ssa_thorin_no_die);
diag
} }
thorin::Error::NoDie => build(fluent::codegen_ssa_thorin_no_die),
thorin::Error::TopLevelDieNotUnit => { thorin::Error::TopLevelDieNotUnit => {
diag = build(fluent::codegen_ssa_thorin_top_level_die_not_unit); build(fluent::codegen_ssa_thorin_top_level_die_not_unit)
diag
} }
thorin::Error::MissingRequiredSection(section) => { thorin::Error::MissingRequiredSection(section) => {
diag = build(fluent::codegen_ssa_thorin_missing_required_section); build(fluent::codegen_ssa_thorin_missing_required_section)
diag.arg("section", section); .arg_mv("section", section)
diag
} }
thorin::Error::ParseUnitAbbreviations(_) => { thorin::Error::ParseUnitAbbreviations(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_unit_abbreviations); build(fluent::codegen_ssa_thorin_parse_unit_abbreviations)
diag
} }
thorin::Error::ParseUnitAttribute(_) => { thorin::Error::ParseUnitAttribute(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_unit_attribute); build(fluent::codegen_ssa_thorin_parse_unit_attribute)
diag
} }
thorin::Error::ParseUnitHeader(_) => { thorin::Error::ParseUnitHeader(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_unit_header); build(fluent::codegen_ssa_thorin_parse_unit_header)
diag
}
thorin::Error::ParseUnit(_) => {
diag = build(fluent::codegen_ssa_thorin_parse_unit);
diag
} }
thorin::Error::ParseUnit(_) => build(fluent::codegen_ssa_thorin_parse_unit),
thorin::Error::IncompatibleIndexVersion(section, format, actual) => { thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
diag = build(fluent::codegen_ssa_thorin_incompatible_index_version); build(fluent::codegen_ssa_thorin_incompatible_index_version)
diag.arg("section", section); .arg_mv("section", section)
diag.arg("actual", actual); .arg_mv("actual", actual)
diag.arg("format", format); .arg_mv("format", format)
diag
} }
thorin::Error::OffsetAtIndex(_, index) => { thorin::Error::OffsetAtIndex(_, index) => {
diag = build(fluent::codegen_ssa_thorin_offset_at_index); build(fluent::codegen_ssa_thorin_offset_at_index).arg_mv("index", index)
diag.arg("index", index);
diag
} }
thorin::Error::StrAtOffset(_, offset) => { thorin::Error::StrAtOffset(_, offset) => {
diag = build(fluent::codegen_ssa_thorin_str_at_offset); build(fluent::codegen_ssa_thorin_str_at_offset)
diag.arg("offset", format!("0x{offset:08x}")); .arg_mv("offset", format!("0x{offset:08x}"))
diag
} }
thorin::Error::ParseIndex(_, section) => { thorin::Error::ParseIndex(_, section) => {
diag = build(fluent::codegen_ssa_thorin_parse_index); build(fluent::codegen_ssa_thorin_parse_index).arg_mv("section", section)
diag.arg("section", section);
diag
} }
thorin::Error::UnitNotInIndex(unit) => { thorin::Error::UnitNotInIndex(unit) => {
diag = build(fluent::codegen_ssa_thorin_unit_not_in_index); build(fluent::codegen_ssa_thorin_unit_not_in_index)
diag.arg("unit", format!("0x{unit:08x}")); .arg_mv("unit", format!("0x{unit:08x}"))
diag
} }
thorin::Error::RowNotInIndex(_, row) => { thorin::Error::RowNotInIndex(_, row) => {
diag = build(fluent::codegen_ssa_thorin_row_not_in_index); build(fluent::codegen_ssa_thorin_row_not_in_index).arg_mv("row", row)
diag.arg("row", row);
diag
}
thorin::Error::SectionNotInRow => {
diag = build(fluent::codegen_ssa_thorin_section_not_in_row);
diag
} }
thorin::Error::SectionNotInRow => build(fluent::codegen_ssa_thorin_section_not_in_row),
thorin::Error::EmptyUnit(unit) => { thorin::Error::EmptyUnit(unit) => {
diag = build(fluent::codegen_ssa_thorin_empty_unit); build(fluent::codegen_ssa_thorin_empty_unit).arg_mv("unit", format!("0x{unit:08x}"))
diag.arg("unit", format!("0x{unit:08x}"));
diag
} }
thorin::Error::MultipleDebugInfoSection => { thorin::Error::MultipleDebugInfoSection => {
diag = build(fluent::codegen_ssa_thorin_multiple_debug_info_section); build(fluent::codegen_ssa_thorin_multiple_debug_info_section)
diag
} }
thorin::Error::MultipleDebugTypesSection => { thorin::Error::MultipleDebugTypesSection => {
diag = build(fluent::codegen_ssa_thorin_multiple_debug_types_section); build(fluent::codegen_ssa_thorin_multiple_debug_types_section)
diag
}
thorin::Error::NotSplitUnit => {
diag = build(fluent::codegen_ssa_thorin_not_split_unit);
diag
}
thorin::Error::DuplicateUnit(unit) => {
diag = build(fluent::codegen_ssa_thorin_duplicate_unit);
diag.arg("unit", format!("0x{unit:08x}"));
diag
} }
thorin::Error::NotSplitUnit => build(fluent::codegen_ssa_thorin_not_split_unit),
thorin::Error::DuplicateUnit(unit) => build(fluent::codegen_ssa_thorin_duplicate_unit)
.arg_mv("unit", format!("0x{unit:08x}")),
thorin::Error::MissingReferencedUnit(unit) => { thorin::Error::MissingReferencedUnit(unit) => {
diag = build(fluent::codegen_ssa_thorin_missing_referenced_unit); build(fluent::codegen_ssa_thorin_missing_referenced_unit)
diag.arg("unit", format!("0x{unit:08x}")); .arg_mv("unit", format!("0x{unit:08x}"))
diag
} }
thorin::Error::NoOutputObjectCreated => { thorin::Error::NoOutputObjectCreated => {
diag = build(fluent::codegen_ssa_thorin_not_output_object_created); build(fluent::codegen_ssa_thorin_not_output_object_created)
diag
} }
thorin::Error::MixedInputEncodings => { thorin::Error::MixedInputEncodings => {
diag = build(fluent::codegen_ssa_thorin_mixed_input_encodings); build(fluent::codegen_ssa_thorin_mixed_input_encodings)
diag
} }
thorin::Error::Io(e) => { thorin::Error::Io(e) => {
diag = build(fluent::codegen_ssa_thorin_io); build(fluent::codegen_ssa_thorin_io).arg_mv("error", format!("{e}"))
diag.arg("error", format!("{e}"));
diag
} }
thorin::Error::ObjectRead(e) => { thorin::Error::ObjectRead(e) => {
diag = build(fluent::codegen_ssa_thorin_object_read); build(fluent::codegen_ssa_thorin_object_read).arg_mv("error", format!("{e}"))
diag.arg("error", format!("{e}"));
diag
} }
thorin::Error::ObjectWrite(e) => { thorin::Error::ObjectWrite(e) => {
diag = build(fluent::codegen_ssa_thorin_object_write); build(fluent::codegen_ssa_thorin_object_write).arg_mv("error", format!("{e}"))
diag.arg("error", format!("{e}"));
diag
} }
thorin::Error::GimliRead(e) => { thorin::Error::GimliRead(e) => {
diag = build(fluent::codegen_ssa_thorin_gimli_read); build(fluent::codegen_ssa_thorin_gimli_read).arg_mv("error", format!("{e}"))
diag.arg("error", format!("{e}"));
diag
} }
thorin::Error::GimliWrite(e) => { thorin::Error::GimliWrite(e) => {
diag = build(fluent::codegen_ssa_thorin_gimli_write); build(fluent::codegen_ssa_thorin_gimli_write).arg_mv("error", format!("{e}"))
diag.arg("error", format!("{e}"));
diag
} }
_ => unimplemented!("Untranslated thorin error"), _ => unimplemented!("Untranslated thorin error"),
} }

View file

@ -30,9 +30,7 @@ where
G: EmissionGuarantee, G: EmissionGuarantee,
{ {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
let mut diag = self.node.into_diagnostic(dcx, level); self.node.into_diagnostic(dcx, level).span_mv(self.span)
diag.span(self.span);
diag
} }
} }

View file

@ -249,60 +249,43 @@ impl<Id> IntoDiagnosticArg for hir::def::Res<Id> {
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_> { impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_> {
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
let mut diag;
match self { match self {
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space)
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space); .arg_mv("addr_space", addr_space)
diag.arg("addr_space", addr_space); .arg_mv("cause", cause)
diag.arg("cause", cause); .arg_mv("err", err)
diag.arg("err", err);
diag
} }
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits); DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits)
diag.arg("kind", kind); .arg_mv("kind", kind)
diag.arg("bit", bit); .arg_mv("bit", bit)
diag.arg("cause", cause); .arg_mv("cause", cause)
diag.arg("err", err); .arg_mv("err", err)
diag
} }
TargetDataLayoutErrors::MissingAlignment { cause } => { TargetDataLayoutErrors::MissingAlignment { cause } => {
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment); DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment)
diag.arg("cause", cause); .arg_mv("cause", cause)
diag
} }
TargetDataLayoutErrors::InvalidAlignment { cause, err } => { TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment); DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment)
diag.arg("cause", cause); .arg_mv("cause", cause)
diag.arg("err_kind", err.diag_ident()); .arg_mv("err_kind", err.diag_ident())
diag.arg("align", err.align()); .arg_mv("align", err.align())
diag
} }
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
diag = DiagnosticBuilder::new( DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_architecture)
dcx, .arg_mv("dl", dl)
level, .arg_mv("target", target)
fluent::errors_target_inconsistent_architecture,
);
diag.arg("dl", dl);
diag.arg("target", target);
diag
} }
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
diag = DiagnosticBuilder::new( DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
dcx, .arg_mv("pointer_size", pointer_size)
level, .arg_mv("target", target)
fluent::errors_target_inconsistent_pointer_width,
);
diag.arg("pointer_size", pointer_size);
diag.arg("target", target);
diag
} }
TargetDataLayoutErrors::InvalidBitsSize { err } => { TargetDataLayoutErrors::InvalidBitsSize { err } => {
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size); DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size)
diag.arg("err", err); .arg_mv("err", err)
diag
} }
} }
} }

View file

@ -729,9 +729,7 @@ impl DiagCtxt {
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, ()> { ) -> DiagnosticBuilder<'_, ()> {
let mut result = self.struct_warn(msg); self.struct_warn(msg).span_mv(span)
result.span(span);
result
} }
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`. /// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
@ -744,9 +742,7 @@ impl DiagCtxt {
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
code: DiagnosticId, code: DiagnosticId,
) -> DiagnosticBuilder<'_, ()> { ) -> DiagnosticBuilder<'_, ()> {
let mut result = self.struct_span_warn(span, msg); self.struct_span_warn(span, msg).code_mv(code)
result.code(code);
result
} }
/// Construct a builder at the `Warning` level with the `msg`. /// Construct a builder at the `Warning` level with the `msg`.
@ -786,9 +782,7 @@ impl DiagCtxt {
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_> { ) -> DiagnosticBuilder<'_> {
let mut result = self.struct_err(msg); self.struct_err(msg).span_mv(span)
result.span(span);
result
} }
/// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`. /// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`.
@ -800,9 +794,7 @@ impl DiagCtxt {
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
code: DiagnosticId, code: DiagnosticId,
) -> DiagnosticBuilder<'_> { ) -> DiagnosticBuilder<'_> {
let mut result = self.struct_span_err(span, msg); self.struct_span_err(span, msg).code_mv(code)
result.code(code);
result
} }
/// Construct a builder at the `Error` level with the `msg`. /// Construct a builder at the `Error` level with the `msg`.
@ -821,9 +813,7 @@ impl DiagCtxt {
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
code: DiagnosticId, code: DiagnosticId,
) -> DiagnosticBuilder<'_> { ) -> DiagnosticBuilder<'_> {
let mut result = self.struct_err(msg); self.struct_err(msg).code_mv(code)
result.code(code);
result
} }
/// Construct a builder at the `Warn` level with the `msg` and the `code`. /// Construct a builder at the `Warn` level with the `msg` and the `code`.
@ -834,9 +824,7 @@ impl DiagCtxt {
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
code: DiagnosticId, code: DiagnosticId,
) -> DiagnosticBuilder<'_, ()> { ) -> DiagnosticBuilder<'_, ()> {
let mut result = self.struct_warn(msg); self.struct_warn(msg).code_mv(code)
result.code(code);
result
} }
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`. /// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
@ -847,9 +835,7 @@ impl DiagCtxt {
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, FatalAbort> { ) -> DiagnosticBuilder<'_, FatalAbort> {
let mut result = self.struct_fatal(msg); self.struct_fatal(msg).span_mv(span)
result.span(span);
result
} }
/// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`. /// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`.
@ -861,9 +847,7 @@ impl DiagCtxt {
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
code: DiagnosticId, code: DiagnosticId,
) -> DiagnosticBuilder<'_, FatalAbort> { ) -> DiagnosticBuilder<'_, FatalAbort> {
let mut result = self.struct_span_fatal(span, msg); self.struct_span_fatal(span, msg).code_mv(code)
result.code(code);
result
} }
/// Construct a builder at the `Fatal` level with the `msg`. /// Construct a builder at the `Fatal` level with the `msg`.
@ -904,9 +888,7 @@ impl DiagCtxt {
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, BugAbort> { ) -> DiagnosticBuilder<'_, BugAbort> {
let mut result = self.struct_bug(msg); self.struct_bug(msg).span_mv(span)
result.span(span);
result
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
@ -1021,9 +1003,7 @@ impl DiagCtxt {
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, ()> { ) -> DiagnosticBuilder<'_, ()> {
let mut db = DiagnosticBuilder::new(self, Note, msg); DiagnosticBuilder::new(self, Note, msg).span_mv(span)
db.span(span);
db
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]

View file

@ -1921,10 +1921,8 @@ fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), Error
} }
fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) -> DiagnosticBuilder<'_> { fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) -> DiagnosticBuilder<'_> {
let mut err = struct_span_err!(tcx.dcx(), span, E0392, "parameter `{param_name}` is never used")
struct_span_err!(tcx.dcx(), span, E0392, "parameter `{param_name}` is never used"); .span_label_mv(span, "unused parameter")
err.span_label(span, "unused parameter");
err
} }
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {

View file

@ -2836,15 +2836,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn private_field_err(&self, field: Ident, base_did: DefId) -> DiagnosticBuilder<'_> { fn private_field_err(&self, field: Ident, base_did: DefId) -> DiagnosticBuilder<'_> {
let struct_path = self.tcx().def_path_str(base_did); let struct_path = self.tcx().def_path_str(base_did);
let kind_name = self.tcx().def_descr(base_did); let kind_name = self.tcx().def_descr(base_did);
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
field.span, field.span,
E0616, E0616,
"field `{field}` of {kind_name} `{struct_path}` is private", "field `{field}` of {kind_name} `{struct_path}` is private",
); )
err.span_label(field.span, "private field"); .span_label_mv(field.span, "private field")
err
} }
pub(crate) fn get_field_candidates_considering_privacy( pub(crate) fn get_field_candidates_considering_privacy(

View file

@ -367,9 +367,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
&trace.cause.code().peel_derives() &trace.cause.code().peel_derives()
{ {
let span = *span; let span = *span;
let mut err = self.report_concrete_failure(placeholder_origin, sub, sup); self.report_concrete_failure(placeholder_origin, sub, sup)
err.span_note(span, "the lifetime requirement is introduced here"); .span_note_mv(span, "the lifetime requirement is introduced here")
err
} else { } else {
unreachable!( unreachable!(
"control flow ensures we have a `BindingObligation` or `ExprBindingObligation` here..." "control flow ensures we have a `BindingObligation` or `ExprBindingObligation` here..."

View file

@ -249,9 +249,9 @@ impl<'a> StringReader<'a> {
let lifetime_name = self.str_from(start); let lifetime_name = self.str_from(start);
if starts_with_number { if starts_with_number {
let span = self.mk_sp(start, self.pos); let span = self.mk_sp(start, self.pos);
let mut diag = self.dcx().struct_err("lifetimes cannot start with a number"); self.dcx().struct_err("lifetimes cannot start with a number")
diag.span(span); .span_mv(span)
diag.stash(span, StashKey::LifetimeIsChar); .stash(span, StashKey::LifetimeIsChar);
} }
let ident = Symbol::intern(lifetime_name); let ident = Symbol::intern(lifetime_name);
token::Lifetime(ident) token::Lifetime(ident)

View file

@ -200,23 +200,22 @@ impl<'a> Parser<'a> {
if let InnerAttrPolicy::Forbidden(reason) = policy { if let InnerAttrPolicy::Forbidden(reason) = policy {
let mut diag = match reason.as_ref().copied() { let mut diag = match reason.as_ref().copied() {
Some(InnerAttrForbiddenReason::AfterOuterDocComment { prev_doc_comment_span }) => { Some(InnerAttrForbiddenReason::AfterOuterDocComment { prev_doc_comment_span }) => {
let mut diag = self.dcx().struct_span_err( self.dcx()
.struct_span_err(
attr_sp, attr_sp,
fluent::parse_inner_attr_not_permitted_after_outer_doc_comment, fluent::parse_inner_attr_not_permitted_after_outer_doc_comment,
); )
diag.span_label(attr_sp, fluent::parse_label_attr) .span_label_mv(attr_sp, fluent::parse_label_attr)
.span_label(prev_doc_comment_span, fluent::parse_label_prev_doc_comment); .span_label_mv(prev_doc_comment_span, fluent::parse_label_prev_doc_comment)
diag
} }
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => { Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => self
let mut diag = self.dcx().struct_span_err( .dcx()
.struct_span_err(
attr_sp, attr_sp,
fluent::parse_inner_attr_not_permitted_after_outer_attr, fluent::parse_inner_attr_not_permitted_after_outer_attr,
); )
diag.span_label(attr_sp, fluent::parse_label_attr) .span_label_mv(attr_sp, fluent::parse_label_attr)
.span_label(prev_outer_attr_sp, fluent::parse_label_prev_attr); .span_label_mv(prev_outer_attr_sp, fluent::parse_label_prev_attr),
diag
}
Some(InnerAttrForbiddenReason::InCodeBlock) | None => { Some(InnerAttrForbiddenReason::InCodeBlock) | None => {
self.dcx().struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted) self.dcx().struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted)
} }

View file

@ -1941,15 +1941,14 @@ impl<'a> Parser<'a> {
Case::Insensitive, Case::Insensitive,
) { ) {
Ok(_) => { Ok(_) => {
let mut err = self.dcx().struct_span_err( self.dcx().struct_span_err(
lo.to(self.prev_token.span), lo.to(self.prev_token.span),
format!("functions are not allowed in {adt_ty} definitions"), format!("functions are not allowed in {adt_ty} definitions"),
); )
err.help( .help_mv(
"unlike in C++, Java, and C#, functions are declared in `impl` blocks", "unlike in C++, Java, and C#, functions are declared in `impl` blocks",
); )
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information"); .help_mv("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information")
err
} }
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
@ -1959,14 +1958,13 @@ impl<'a> Parser<'a> {
} }
} else if self.eat_keyword(kw::Struct) { } else if self.eat_keyword(kw::Struct) {
match self.parse_item_struct() { match self.parse_item_struct() {
Ok((ident, _)) => { Ok((ident, _)) => self
let mut err = self.dcx().struct_span_err( .dcx()
.struct_span_err(
lo.with_hi(ident.span.hi()), lo.with_hi(ident.span.hi()),
format!("structs are not allowed in {adt_ty} definitions"), format!("structs are not allowed in {adt_ty} definitions"),
); )
err.help("consider creating a new `struct` definition instead of nesting"); .help_mv("consider creating a new `struct` definition instead of nesting"),
err
}
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
self.restore_snapshot(snapshot); self.restore_snapshot(snapshot);

View file

@ -460,9 +460,10 @@ impl<'a> Parser<'a> {
super::token_descr(&self_.token) super::token_descr(&self_.token)
); );
let mut err = self_.dcx().struct_span_err(self_.token.span, msg); self_
err.span_label(self_.token.span, format!("expected {expected}")); .dcx()
err .struct_span_err(self_.token.span, msg)
.span_label_mv(self_.token.span, format!("expected {expected}"))
}); });
PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit))) PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit)))
} else { } else {

View file

@ -944,16 +944,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
trait_item_span, trait_item_span,
trait_path, trait_path,
} => { } => {
let mut err = self.dcx().struct_span_err_with_code( self.dcx().struct_span_err_with_code(
span, span,
format!( format!(
"item `{name}` is an associated {kind}, which doesn't match its trait `{trait_path}`", "item `{name}` is an associated {kind}, which doesn't match its trait `{trait_path}`",
), ),
code, code,
); )
err.span_label(span, "does not match trait"); .span_label_mv(span, "does not match trait")
err.span_label(trait_item_span, "item in trait"); .span_label_mv(trait_item_span, "item in trait")
err
} }
ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self
.dcx() .dcx()

View file

@ -2603,25 +2603,23 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
) { ) {
debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime); debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime);
let mut err = if let Some(outer) = outer_lifetime_ref { let mut err = if let Some(outer) = outer_lifetime_ref {
let mut err = struct_span_err!( struct_span_err!(
self.r.dcx(), self.r.dcx(),
lifetime_ref.ident.span, lifetime_ref.ident.span,
E0401, E0401,
"can't use generic parameters from outer item", "can't use generic parameters from outer item",
); )
err.span_label(lifetime_ref.ident.span, "use of generic parameter from outer item"); .span_label_mv(lifetime_ref.ident.span, "use of generic parameter from outer item")
err.span_label(outer.span, "lifetime parameter from outer item"); .span_label_mv(outer.span, "lifetime parameter from outer item")
err
} else { } else {
let mut err = struct_span_err!( struct_span_err!(
self.r.dcx(), self.r.dcx(),
lifetime_ref.ident.span, lifetime_ref.ident.span,
E0261, E0261,
"use of undeclared lifetime name `{}`", "use of undeclared lifetime name `{}`",
lifetime_ref.ident lifetime_ref.ident
); )
err.span_label(lifetime_ref.ident.span, "undeclared lifetime"); .span_label_mv(lifetime_ref.ident.span, "undeclared lifetime")
err
}; };
self.suggest_introducing_lifetime( self.suggest_introducing_lifetime(
&mut err, &mut err,

View file

@ -18,10 +18,9 @@ pub struct FeatureGateError {
impl<'a> IntoDiagnostic<'a> for FeatureGateError { impl<'a> IntoDiagnostic<'a> for FeatureGateError {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> { fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> {
let mut diag = DiagnosticBuilder::new(dcx, level, self.explain); DiagnosticBuilder::new(dcx, level, self.explain)
diag.span(self.span); .span_mv(self.span)
diag.code(error_code!(E0658)); .code_mv(error_code!(E0658))
diag
} }
} }

View file

@ -18,9 +18,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TestOutput {
let TestOutput { span, kind, content } = self; let TestOutput { span, kind, content } = self;
#[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::untranslatable_diagnostic)]
let mut diag = DiagnosticBuilder::new(dcx, level, format!("{kind}({content})")); DiagnosticBuilder::new(dcx, level, format!("{kind}({content})")).span_mv(span)
diag.span(span);
diag
} }
} }

View file

@ -2654,26 +2654,24 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.chain(Some(data.term.into_arg())) .chain(Some(data.term.into_arg()))
.find(|g| g.has_non_region_infer()); .find(|g| g.has_non_region_infer());
if let Some(subst) = subst { if let Some(subst) = subst {
let mut err = self.emit_inference_failure_err( self.emit_inference_failure_err(
obligation.cause.body_id, obligation.cause.body_id,
span, span,
subst, subst,
ErrorCode::E0284, ErrorCode::E0284,
true, true,
); )
err.note(format!("cannot satisfy `{predicate}`")); .note_mv(format!("cannot satisfy `{predicate}`"))
err
} else { } else {
// If we can't find a substitution, just print a generic error // If we can't find a substitution, just print a generic error
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0284, E0284,
"type annotations needed: cannot satisfy `{}`", "type annotations needed: cannot satisfy `{}`",
predicate, predicate,
); )
err.span_label(span, format!("cannot satisfy `{predicate}`")); .span_label_mv(span, format!("cannot satisfy `{predicate}`"))
err
} }
} }
@ -2693,30 +2691,28 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err err
} else { } else {
// If we can't find a substitution, just print a generic error // If we can't find a substitution, just print a generic error
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0284, E0284,
"type annotations needed: cannot satisfy `{}`", "type annotations needed: cannot satisfy `{}`",
predicate, predicate,
); )
err.span_label(span, format!("cannot satisfy `{predicate}`")); .span_label_mv(span, format!("cannot satisfy `{predicate}`"))
err
} }
} }
_ => { _ => {
if self.dcx().has_errors().is_some() || self.tainted_by_errors().is_some() { if self.dcx().has_errors().is_some() || self.tainted_by_errors().is_some() {
return; return;
} }
let mut err = struct_span_err!( struct_span_err!(
self.dcx(), self.dcx(),
span, span,
E0284, E0284,
"type annotations needed: cannot satisfy `{}`", "type annotations needed: cannot satisfy `{}`",
predicate, predicate,
); )
err.span_label(span, format!("cannot satisfy `{predicate}`")); .span_label_mv(span, format!("cannot satisfy `{predicate}`"))
err
} }
}; };
self.note_obligation_cause(&mut err, obligation); self.note_obligation_cause(&mut err, obligation);