1
- use crate :: error:: TranslateError ;
1
+ use crate :: error:: { TranslateError , TranslateErrorKind } ;
2
2
use crate :: snippet:: Style ;
3
3
use crate :: { DiagnosticArg , DiagnosticMessage , FluentBundle } ;
4
4
use rustc_data_structures:: sync:: Lrc ;
@@ -95,6 +95,16 @@ pub trait Translate {
95
95
// The primary bundle was present and translation succeeded
96
96
Some ( Ok ( t) ) => t,
97
97
98
+ // If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
99
+ // just that the primary bundle doesn't contain the message being translated, so
100
+ // proceed to the fallback bundle.
101
+ Some ( Err (
102
+ primary @ TranslateError :: One {
103
+ kind : TranslateErrorKind :: MessageMissing , ..
104
+ } ,
105
+ ) ) => translate_with_bundle ( self . fallback_fluent_bundle ( ) )
106
+ . map_err ( |fallback| primary. and ( fallback) ) ?,
107
+
98
108
// Always yeet out for errors on debug (unless
99
109
// `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
100
110
// local runs of the test suites, of builds with debug assertions, to test the
@@ -106,9 +116,8 @@ pub trait Translate {
106
116
do yeet primary
107
117
}
108
118
109
- // If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
110
- // just that the primary bundle doesn't contain the message being translated or
111
- // something else went wrong) so proceed to the fallback bundle.
119
+ // ..otherwise, for end users, an error about this wouldn't be useful or actionable, so
120
+ // just hide it and try with the fallback bundle.
112
121
Some ( Err ( primary) ) => translate_with_bundle ( self . fallback_fluent_bundle ( ) )
113
122
. map_err ( |fallback| primary. and ( fallback) ) ?,
114
123
0 commit comments