@@ -43,6 +43,45 @@ pub trait DateTimeNamesMarker: UnstableSealed {
43
43
type MetazoneLookup : NamesContainer < tz:: MzPeriodV1 , ( ) > ;
44
44
}
45
45
46
+ /// A trait for `Variables` that can be converted to [`ErrorField`]
47
+ pub trait MaybeAsErrorField : UnstableSealed {
48
+ fn maybe_as_error_field ( & self ) -> Option < ErrorField > ;
49
+ }
50
+
51
+ impl MaybeAsErrorField for ( ) {
52
+ fn maybe_as_error_field ( & self ) -> Option < ErrorField > {
53
+ None
54
+ }
55
+ }
56
+
57
+ impl UnstableSealed for YearNameLength { }
58
+ impl MaybeAsErrorField for YearNameLength {
59
+ fn maybe_as_error_field ( & self ) -> Option < ErrorField > {
60
+ Some ( self . to_approximate_error_field ( ) )
61
+ }
62
+ }
63
+
64
+ impl UnstableSealed for MonthNameLength { }
65
+ impl MaybeAsErrorField for MonthNameLength {
66
+ fn maybe_as_error_field ( & self ) -> Option < ErrorField > {
67
+ Some ( self . to_approximate_error_field ( ) )
68
+ }
69
+ }
70
+
71
+ impl UnstableSealed for WeekdayNameLength { }
72
+ impl MaybeAsErrorField for WeekdayNameLength {
73
+ fn maybe_as_error_field ( & self ) -> Option < ErrorField > {
74
+ Some ( self . to_approximate_error_field ( ) )
75
+ }
76
+ }
77
+
78
+ impl UnstableSealed for DayPeriodNameLength { }
79
+ impl MaybeAsErrorField for DayPeriodNameLength {
80
+ fn maybe_as_error_field ( & self ) -> Option < ErrorField > {
81
+ Some ( self . to_approximate_error_field ( ) )
82
+ }
83
+ }
84
+
46
85
/// Trait that associates a container for a payload parameterized by the given variables.
47
86
///
48
87
/// <div class="stab unstable">
@@ -69,7 +108,7 @@ macro_rules! impl_holder_trait {
69
108
impl UnstableSealed for $marker { }
70
109
impl <Variables > NamesContainer <$marker, Variables > for $marker
71
110
where
72
- Variables : PartialEq + Copy + fmt:: Debug ,
111
+ Variables : PartialEq + Copy + MaybeAsErrorField + fmt:: Debug ,
73
112
{
74
113
type Container = DataPayloadWithVariables <$marker, Variables >;
75
114
}
@@ -97,10 +136,10 @@ impl_holder_trait!(tz::MzPeriodV1);
97
136
#[ derive( Debug , displaydoc:: Display ) ]
98
137
#[ non_exhaustive]
99
138
pub enum MaybePayloadError {
100
- /// TODO
139
+ /// The container's field set doesn't support the field
101
140
FormatterTooSpecific ,
102
- /// TODO
103
- ConflictingField ,
141
+ /// The field is already loaded with a different length
142
+ ConflictingField ( ErrorField ) ,
104
143
}
105
144
106
145
impl core:: error:: Error for MaybePayloadError { }
@@ -109,7 +148,10 @@ impl MaybePayloadError {
109
148
pub ( crate ) fn into_load_error ( self , error_field : ErrorField ) -> PatternLoadError {
110
149
match self {
111
150
Self :: FormatterTooSpecific => PatternLoadError :: FormatterTooSpecific ( error_field) ,
112
- Self :: ConflictingField => PatternLoadError :: ConflictingField ( error_field) ,
151
+ Self :: ConflictingField ( loaded_field) => PatternLoadError :: ConflictingField {
152
+ requested_field : error_field,
153
+ loaded_field,
154
+ } ,
113
155
}
114
156
}
115
157
}
@@ -200,7 +242,7 @@ where
200
242
impl < M : DynamicDataMarker , Variables > MaybePayload < M , Variables >
201
243
for DataPayloadWithVariables < M , Variables >
202
244
where
203
- Variables : PartialEq + Copy ,
245
+ Variables : PartialEq + Copy + MaybeAsErrorField ,
204
246
{
205
247
#[ inline]
206
248
fn new_empty ( ) -> Self {
@@ -224,8 +266,19 @@ where
224
266
// TODO(#6063): probably not correct
225
267
return Ok ( Ok ( Default :: default ( ) ) ) ;
226
268
}
227
- OptionalNames :: SingleLength { .. } => {
228
- return Err ( MaybePayloadError :: ConflictingField ) ;
269
+ OptionalNames :: SingleLength { variables, .. } => {
270
+ let loaded_field = match variables. maybe_as_error_field ( ) {
271
+ Some ( x) => x,
272
+ None => {
273
+ debug_assert ! ( false , "all non-unit variables implement this trait" ) ;
274
+ use crate :: provider:: fields:: * ;
275
+ ErrorField ( Field {
276
+ symbol : FieldSymbol :: Era ,
277
+ length : FieldLength :: Six ,
278
+ } )
279
+ }
280
+ } ;
281
+ return Err ( MaybePayloadError :: ConflictingField ( loaded_field) ) ;
229
282
}
230
283
OptionalNames :: None => ( ) ,
231
284
} ;
0 commit comments