errors: introduce DiagnosticMessage

Introduce a `DiagnosticMessage` type that will enable diagnostic
messages to be simple strings or Fluent identifiers.
`DiagnosticMessage` is now used in the implementation of the standard
`DiagnosticBuilder` APIs.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-03-23 07:34:20 +00:00
parent a22cf2af05
commit 8c684563a5
10 changed files with 79 additions and 43 deletions

View file

@ -346,7 +346,7 @@ struct UnusedExterns<'a, 'b, 'c> {
impl Diagnostic {
fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnostic {
let sugg = diag.suggestions.iter().flatten().map(|sugg| Diagnostic {
message: sugg.msg.clone(),
message: sugg.msg.clone().to_string(),
code: None,
level: "help",
spans: DiagnosticSpan::from_suggestion(sugg, je),
@ -385,7 +385,7 @@ impl Diagnostic {
let output = String::from_utf8(output).unwrap();
Diagnostic {
message: diag.message(),
message: diag.message().to_string(),
code: DiagnosticCode::map_opt_string(diag.code.clone(), je),
level: diag.level.to_str(),
spans: DiagnosticSpan::from_multispan(&diag.span, je),
@ -402,7 +402,7 @@ impl Diagnostic {
fn from_sub_diagnostic(diag: &SubDiagnostic, je: &JsonEmitter) -> Diagnostic {
Diagnostic {
message: diag.message(),
message: diag.message().to_string(),
code: None,
level: diag.level.to_str(),
spans: diag