X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_error_messages%2Fsrc%2Flib.rs;h=f053bdc3809be30d5377cae4abc3960f503644b9;hb=bf321ece1e5756493b1ac061cd87a48123cda52c;hp=418ba3c74d7761cb574d8ad0840fd0dd09c93249;hpb=4fdc3eb1761ee50961e4da67b7ccda9d971f5f20;p=rust.git diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 418ba3c74d7..f053bdc3809 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -57,6 +57,7 @@ lint => "../locales/en-US/lint.ftl", metadata => "../locales/en-US/metadata.ftl", middle => "../locales/en-US/middle.ftl", + mir_build => "../locales/en-US/mir_build.ftl", mir_dataflow => "../locales/en-US/mir_dataflow.ftl", monomorphize => "../locales/en-US/monomorphize.ftl", parse => "../locales/en-US/parse.ftl", @@ -181,6 +182,9 @@ pub fn fluent_bundle( trace!(?locale); let mut bundle = new_bundle(vec![locale]); + // Add convenience functions available to ftl authors. + register_functions(&mut bundle); + // Fluent diagnostics can insert directionality isolation markers around interpolated variables // indicating that there may be a shift from right-to-left to left-to-right text (or // vice-versa). These are disabled because they are sometimes visible in the error output, but @@ -243,6 +247,15 @@ pub fn fluent_bundle( Ok(Some(bundle)) } +fn register_functions(bundle: &mut FluentBundle) { + bundle + .add_function("STREQ", |positional, _named| match positional { + [FluentValue::String(a), FluentValue::String(b)] => format!("{}", (a == b)).into(), + _ => FluentValue::Error, + }) + .expect("Failed to add a function to the bundle."); +} + /// Type alias for the result of `fallback_fluent_bundle` - a reference-counted pointer to a lazily /// evaluated fluent bundle. pub type LazyFallbackBundle = Lrc FluentBundle>>; @@ -255,6 +268,9 @@ pub fn fallback_fluent_bundle( ) -> LazyFallbackBundle { Lrc::new(Lazy::new(move || { let mut fallback_bundle = new_bundle(vec![langid!("en-US")]); + + register_functions(&mut fallback_bundle); + // See comment in `fluent_bundle`. fallback_bundle.set_use_isolating(with_directionality_markers); @@ -380,7 +396,7 @@ fn from(s: S) -> Self { } } -/// A workaround for "good path" ICEs when formatting types in disables lints. +/// A workaround for "good path" ICEs when formatting types in disabled lints. /// /// Delays formatting until `.into(): DiagnosticMessage` is used. pub struct DelayDm(pub F); @@ -548,9 +564,7 @@ fn icu_locale_from_unic_langid(lang: LanguageIdentifier) -> Option( - l: Vec>, -) -> FluentValue<'source> { +pub fn fluent_value_from_str_list_sep_by_and(l: Vec>) -> FluentValue<'_> { // Fluent requires 'static value here for its AnyEq usages. #[derive(Clone, PartialEq, Debug)] struct FluentStrListSepByAnd(Vec);