@@ -27,7 +27,11 @@ pub struct SuggestionsDisabled;
27
27
/// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of
28
28
/// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of
29
29
/// diagnostic emission.
30
- pub type DiagnosticArg < ' source > = ( Cow < ' source , str > , DiagnosticArgValue < ' source > ) ;
30
+ pub type DiagnosticArg < ' iter , ' source > =
31
+ ( & ' iter DiagnosticArgName < ' source > , & ' iter DiagnosticArgValue < ' source > ) ;
32
+
33
+ /// Name of a diagnostic argument.
34
+ pub type DiagnosticArgName < ' source > = Cow < ' source , str > ;
31
35
32
36
/// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted
33
37
/// to a `FluentValue` by the emitter to be used in diagnostic translation.
@@ -229,7 +233,7 @@ pub struct Diagnostic {
229
233
pub span : MultiSpan ,
230
234
pub children : Vec < SubDiagnostic > ,
231
235
pub suggestions : Result < Vec < CodeSuggestion > , SuggestionsDisabled > ,
232
- args : Vec < DiagnosticArg < ' static > > ,
236
+ args : FxHashMap < DiagnosticArgName < ' static > , DiagnosticArgValue < ' static > > ,
233
237
234
238
/// This is not used for highlighting or rendering any error message. Rather, it can be used
235
239
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
@@ -321,7 +325,7 @@ impl Diagnostic {
321
325
span : MultiSpan :: new ( ) ,
322
326
children : vec ! [ ] ,
323
327
suggestions : Ok ( vec ! [ ] ) ,
324
- args : vec ! [ ] ,
328
+ args : Default :: default ( ) ,
325
329
sort_span : DUMMY_SP ,
326
330
is_lint : false ,
327
331
}
@@ -956,16 +960,19 @@ impl Diagnostic {
956
960
self
957
961
}
958
962
959
- pub fn args ( & self ) -> & [ DiagnosticArg < ' static > ] {
960
- & self . args
963
+ // Exact iteration order of diagnostic arguments shouldn't make a difference to output because
964
+ // they're only used in interpolation.
965
+ #[ allow( rustc:: potential_query_instability) ]
966
+ pub fn args < ' a > ( & ' a self ) -> impl Iterator < Item = DiagnosticArg < ' a , ' static > > {
967
+ self . args . iter ( )
961
968
}
962
969
963
970
pub fn set_arg (
964
971
& mut self ,
965
972
name : impl Into < Cow < ' static , str > > ,
966
973
arg : impl IntoDiagnosticArg ,
967
974
) -> & mut Self {
968
- self . args . push ( ( name. into ( ) , arg. into_diagnostic_arg ( ) ) ) ;
975
+ self . args . insert ( name. into ( ) , arg. into_diagnostic_arg ( ) ) ;
969
976
self
970
977
}
971
978
0 commit comments