@@ -108,7 +108,6 @@ pub enum DateFromFieldsError {
108108 /// ```
109109 /// use icu_calendar::Date;
110110 /// use icu_calendar::error::DateFromFieldsError;
111- /// use icu_calendar::error::RangeError;
112111 /// use icu_calendar::Iso;
113112 /// use icu_calendar::types::DateFields;
114113 ///
@@ -122,10 +121,20 @@ pub enum DateFromFieldsError {
122121 /// )
123122 /// .expect_err("no month 13 in the ISO calendar");
124123 ///
125- /// assert!(matches!(err, DateFromFieldsError::Range(RangeError { field: "month", .. }) ));
124+ /// assert!(matches!(err, DateFromFieldsError::Range { field: "month", .. }));
126125 /// ```
127- #[ displaydoc( "{0}" ) ]
128- Range ( RangeError ) ,
126+ #[ displaydoc( "The {field} = {value} argument is out of range {min}..={max}" ) ]
127+ #[ non_exhaustive]
128+ Range {
129+ /// The field that is out of range, such as "year"
130+ field : & ' static str ,
131+ /// The actual value
132+ value : i32 ,
133+ /// The minimum value (inclusive). This might not be tight.
134+ min : i32 ,
135+ /// The maximum value (inclusive). This might not be tight.
136+ max : i32 ,
137+ } ,
129138 /// The era code is invalid for the calendar.
130139 #[ displaydoc( "Unknown era or invalid syntax" ) ]
131140 UnknownEra ,
@@ -343,13 +352,6 @@ pub enum DateFromFieldsError {
343352
344353impl core:: error:: Error for DateFromFieldsError { }
345354
346- impl From < RangeError > for DateFromFieldsError {
347- #[ inline]
348- fn from ( value : RangeError ) -> Self {
349- DateFromFieldsError :: Range ( value)
350- }
351- }
352-
353355/// Internal narrow error type for functions that only fail on unknown eras
354356pub ( crate ) struct UnknownEraError ;
355357
@@ -473,6 +475,24 @@ impl From<RangeError> for DateError {
473475 }
474476}
475477
478+ impl From < RangeError > for DateFromFieldsError {
479+ #[ inline]
480+ fn from ( value : RangeError ) -> Self {
481+ let RangeError {
482+ field,
483+ value,
484+ min,
485+ max,
486+ } = value;
487+ DateFromFieldsError :: Range {
488+ field,
489+ value,
490+ min,
491+ max,
492+ }
493+ }
494+ }
495+
476496pub ( crate ) fn range_check_with_overflow < T : Ord + Into < i32 > + Copy > (
477497 value : T ,
478498 field : & ' static str ,
0 commit comments