diff options
| author | bors <bors@rust-lang.org> | 2024-04-04 05:10:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-04 05:10:51 +0000 |
| commit | 394aa87a74a3d37c5643dae13acde583482f0359 (patch) | |
| tree | 0df96b7dd21d20796e58c38a8f7f36413be4a6d8 /compiler/rustc_errors/src | |
| parent | 92509847a7fe4d829c5fb73eef1b839d6b9fdbd8 (diff) | |
| parent | 9c334143d84733cbd26f1698dd9137c09f34a77b (diff) | |
| download | rust-394aa87a74a3d37c5643dae13acde583482f0359.tar.gz rust-394aa87a74a3d37c5643dae13acde583482f0359.zip | |
Auto merge of #3447 - rust-lang:rustup-2024-04-04, r=saethlin
Automatic Rustup
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index c47abf5e988..b4107bd4a2b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1951,6 +1951,39 @@ pub fn report_ambiguity_error<'a, G: EmissionGuarantee>( } } +/// Grammatical tool for displaying messages to end users in a nice form. +/// +/// Returns "an" if the given string starts with a vowel, and "a" otherwise. +pub fn a_or_an(s: &str) -> &'static str { + let mut chars = s.chars(); + let Some(mut first_alpha_char) = chars.next() else { + return "a"; + }; + if first_alpha_char == '`' { + let Some(next) = chars.next() else { + return "a"; + }; + first_alpha_char = next; + } + if ["a", "e", "i", "o", "u", "&"].contains(&&first_alpha_char.to_lowercase().to_string()[..]) { + "an" + } else { + "a" + } +} + +/// Grammatical tool for displaying messages to end users in a nice form. +/// +/// Take a list ["a", "b", "c"] and output a display friendly version "a, b and c" +pub fn display_list_with_comma_and<T: std::fmt::Display>(v: &[T]) -> String { + match v.len() { + 0 => "".to_string(), + 1 => v[0].to_string(), + 2 => format!("{} and {}", v[0], v[1]), + _ => format!("{}, {}", v[0], display_list_with_comma_and(&v[1..])), + } +} + #[derive(Clone, Copy, PartialEq, Hash, Debug)] pub enum TerminalUrl { No, |
