Overhaul Diagnostic args.

First, introduce a typedef `DiagnosticArgMap`.

Second, make the `args` field public, and remove the `args` getter and
`replace_args` setter. These were necessary previously because the getter
had a `#[allow(rustc::potential_query_instability)]` attribute, but that
was removed in #120931 when the args were changed from `FxHashMap` to
`FxIndexMap`. (All the other `Diagnostic` fields are public.)
This commit is contained in:
Nicholas Nethercote 2024-02-16 06:07:49 +11:00
parent f8131a48a4
commit b38ed1afa6
10 changed files with 24 additions and 31 deletions

View file

@ -437,7 +437,7 @@ pub trait ReportErrorExt {
let mut diag = dcx.struct_allow(DiagnosticMessage::Str(String::new().into()));
let message = self.diagnostic_message();
self.add_args(&mut diag);
let s = dcx.eagerly_translate_to_string(message, diag.args());
let s = dcx.eagerly_translate_to_string(message, diag.args.iter());
diag.cancel();
s
})
@ -864,7 +864,7 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
let dummy_level = Level::Bug;
let dummy_diag: DiagnosticBuilder<'_, ()> =
e.into_diagnostic().into_diagnostic(diag.dcx, dummy_level);
for (name, val) in dummy_diag.args() {
for (name, val) in dummy_diag.args.iter() {
diag.arg(name.clone(), val.clone());
}
dummy_diag.cancel();