Skip to content

Commit 2e5193b

Browse files
committed
Add StrListSepByOr
1 parent d114def commit 2e5193b

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

compiler/rustc_baked_icu_data/src/data/macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ pub use __impl_fallback_supplement_co_v1 as impl_fallback_supplement_co_v1;
4545
mod list_and_v1;
4646
#[doc(inline)]
4747
pub use __impl_list_and_v1 as impl_list_and_v1;
48+
#[macro_use]
49+
#[path = "macros/list_or_v1.rs.data"]
50+
mod list_or_v1;
51+
#[doc(inline)]
52+
pub use __impl_list_or_v1 as impl_list_or_v1;

compiler/rustc_baked_icu_data/src/data/macros/list_or_v1.rs.data

Lines changed: 45 additions & 0 deletions
Large diffs are not rendered by default.

compiler/rustc_baked_icu_data/src/data/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ macro_rules! impl_data_provider {
77
impl_fallback_parents_v1!($provider);
88
impl_fallback_supplement_co_v1!($provider);
99
impl_list_and_v1!($provider);
10+
impl_list_or_v1!($provider);
1011
};
1112
}
1213
#[allow(unused_macros)]
@@ -20,6 +21,7 @@ macro_rules! impl_any_provider {
2021
h if h == <icu_locid_transform::provider::LocaleFallbackParentsV1Marker as icu_provider::KeyedDataMarker>::KEY.hashed() => icu_provider::DataProvider::<icu_locid_transform::provider::LocaleFallbackParentsV1Marker>::load(self, req).map(icu_provider::DataResponse::wrap_into_any_response),
2122
h if h == <icu_locid_transform::provider::CollationFallbackSupplementV1Marker as icu_provider::KeyedDataMarker>::KEY.hashed() => icu_provider::DataProvider::<icu_locid_transform::provider::CollationFallbackSupplementV1Marker>::load(self, req).map(icu_provider::DataResponse::wrap_into_any_response),
2223
h if h == <icu_list::provider::AndListV1Marker as icu_provider::KeyedDataMarker>::KEY.hashed() => icu_provider::DataProvider::<icu_list::provider::AndListV1Marker>::load(self, req).map(icu_provider::DataResponse::wrap_into_any_response),
24+
h if h == <icu_list::provider::OrListV1Marker as icu_provider::KeyedDataMarker>::KEY.hashed() => icu_provider::DataProvider::<icu_list::provider::OrListV1Marker>::load(self, req).map(icu_provider::DataResponse::wrap_into_any_response),
2325
_ => Err(icu_provider::DataErrorKind::MissingDataKey.with_req(key, req)),
2426
}
2527
}

compiler/rustc_baked_icu_data/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! ```text
1717
//! icu4x-datagen -W --pretty --fingerprint --use-separate-crates --format mod \
1818
//! -l en es fr it ja pt ru tr zh zh-Hans zh-Hant \
19-
//! -k list/and@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \
19+
//! -k list/and@1 list/or@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \
2020
//! --cldr-tag latest --icuexport-tag latest \
2121
//! -o src/data
2222
//! ```

compiler/rustc_error_messages/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ fn icu_locale_from_unic_langid(lang: LanguageIdentifier) -> Option<icu_locid::Lo
532532
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
533533
enum Separator {
534534
And,
535+
Or,
535536
}
536537

537538
impl Separator {
@@ -546,6 +547,11 @@ impl Separator {
546547
&locale.into(),
547548
icu_list::ListLength::Wide,
548549
),
550+
Separator::Or => icu_list::ListFormatter::try_new_or_with_length_with_any_provider(
551+
&data_provider,
552+
&locale.into(),
553+
icu_list::ListLength::Wide,
554+
),
549555
}
550556
.expect("Failed to create list formatter")
551557
}
@@ -630,3 +636,10 @@ pub fn fluent_value_from_str_list_sep_by_and(l: Vec<Cow<'_, str>>) -> FluentValu
630636

631637
FluentValue::Custom(Box::new(FluentStrListSepBy { sep: Separator::And, items }))
632638
}
639+
640+
pub fn fluent_value_from_str_list_sep_by_or(l: Vec<Cow<'_, str>>) -> FluentValue<'_> {
641+
// Fluent requires 'static value here for its AnyEq usages.
642+
let items = l.into_iter().map(|x| x.into_owned()).collect();
643+
644+
FluentValue::Custom(Box::new(FluentStrListSepBy { sep: Separator::Or, items }))
645+
}

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::panic;
77
use std::thread::panicking;
88

99
use rustc_data_structures::fx::FxIndexMap;
10-
use rustc_error_messages::{fluent_value_from_str_list_sep_by_and, FluentValue};
10+
use rustc_error_messages::{
11+
fluent_value_from_str_list_sep_by_and, fluent_value_from_str_list_sep_by_or, FluentValue,
12+
};
1113
use rustc_lint_defs::{Applicability, LintExpectationId};
1214
use rustc_macros::{Decodable, Encodable};
1315
use rustc_span::source_map::Spanned;
@@ -44,6 +46,7 @@ pub enum DiagArgValue {
4446
// to strings in `into_diag_arg` and stored using the `Str` variant.
4547
Number(i32),
4648
StrListSepByAnd(Vec<Cow<'static, str>>),
49+
StrListSepByOr(Vec<Cow<'static, str>>),
4750
}
4851

4952
pub type DiagArgMap = FxIndexMap<DiagArgName, DiagArgValue>;
@@ -167,6 +170,7 @@ impl Into<FluentValue<'static>> for DiagArgValue {
167170
DiagArgValue::Str(s) => From::from(s),
168171
DiagArgValue::Number(n) => From::from(n),
169172
DiagArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l),
173+
DiagArgValue::StrListSepByOr(l) => fluent_value_from_str_list_sep_by_or(l),
170174
}
171175
}
172176
}

0 commit comments

Comments
 (0)