summary refs log tree commit diff
path: root/compiler/rustc_errors
diff options
context:
space:
mode:
authorCharles Lew <crlf0710@gmail.com>2022-11-06 14:43:25 +0800
committerManish Goregaokar <manishsmail@gmail.com>2022-11-18 14:46:35 -0800
commita775004322df90a564c58e702364c10e6f0192a4 (patch)
treee642e5db8a9478eedaa2735855dbfab7db79d483 /compiler/rustc_errors
parent42d3bda08c0c65c455d8349031f42f074ad42b28 (diff)
downloadrust-a775004322df90a564c58e702364c10e6f0192a4.tar.gz
rust-a775004322df90a564c58e702364c10e6f0192a4.zip
Migrate diagnostics list output to use icu list formatter.
Diffstat (limited to 'compiler/rustc_errors')
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs3
-rw-r--r--compiler/rustc_errors/src/diagnostic_impls.rs21
2 files changed, 6 insertions, 18 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index 66c986977ec..2c1d0037aa6 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -4,6 +4,7 @@ use crate::{
     SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
 };
 use rustc_data_structures::fx::FxHashMap;
+use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
 use rustc_error_messages::FluentValue;
 use rustc_lint_defs::{Applicability, LintExpectationId};
 use rustc_span::edition::LATEST_STABLE_EDITION;
@@ -34,6 +35,7 @@ pub type DiagnosticArgName<'source> = Cow<'source, str>;
 pub enum DiagnosticArgValue<'source> {
     Str(Cow<'source, str>),
     Number(usize),
+    StrListSepByAnd(Vec<Cow<'source, str>>),
 }
 
 /// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic`
@@ -58,6 +60,7 @@ impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
         match self {
             DiagnosticArgValue::Str(s) => From::from(s),
             DiagnosticArgValue::Number(n) => From::from(n),
+            DiagnosticArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l),
         }
     }
 }
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs
index c6035705e39..6716339eaa4 100644
--- a/compiler/rustc_errors/src/diagnostic_impls.rs
+++ b/compiler/rustc_errors/src/diagnostic_impls.rs
@@ -11,7 +11,6 @@ use rustc_target::abi::TargetDataLayoutErrors;
 use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
 use std::borrow::Cow;
 use std::fmt;
-use std::fmt::Write;
 use std::num::ParseIntError;
 use std::path::{Path, PathBuf};
 use std::process::ExitStatus;
@@ -191,23 +190,9 @@ impl From<Vec<Symbol>> for DiagnosticSymbolList {
 
 impl IntoDiagnosticArg for DiagnosticSymbolList {
     fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
-        // FIXME: replace the logic here with a real list formatter
-        let symbols = match &self.0[..] {
-            [symbol] => format!("`{symbol}`"),
-            [symbol, last] => {
-                format!("`{symbol}` and `{last}`",)
-            }
-            [symbols @ .., last] => {
-                let mut result = String::new();
-                for symbol in symbols {
-                    write!(result, "`{symbol}`, ").unwrap();
-                }
-                write!(result, "and `{last}`").unwrap();
-                result
-            }
-            [] => unreachable!(),
-        };
-        DiagnosticArgValue::Str(Cow::Owned(symbols))
+        DiagnosticArgValue::StrListSepByAnd(
+            self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(),
+        )
     }
 }