@@ -27,7 +27,11 @@ pub struct SuggestionsDisabled;
2727/// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of
2828/// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of
2929/// 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 > ;
3135
3236/// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted
3337/// to a `FluentValue` by the emitter to be used in diagnostic translation.
@@ -229,7 +233,7 @@ pub struct Diagnostic {
229233 pub span : MultiSpan ,
230234 pub children : Vec < SubDiagnostic > ,
231235 pub suggestions : Result < Vec < CodeSuggestion > , SuggestionsDisabled > ,
232- args : Vec < DiagnosticArg < ' static > > ,
236+ args : FxHashMap < DiagnosticArgName < ' static > , DiagnosticArgValue < ' static > > ,
233237
234238 /// This is not used for highlighting or rendering any error message. Rather, it can be used
235239 /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
@@ -321,7 +325,7 @@ impl Diagnostic {
321325 span : MultiSpan :: new ( ) ,
322326 children : vec ! [ ] ,
323327 suggestions : Ok ( vec ! [ ] ) ,
324- args : vec ! [ ] ,
328+ args : Default :: default ( ) ,
325329 sort_span : DUMMY_SP ,
326330 is_lint : false ,
327331 }
@@ -956,16 +960,19 @@ impl Diagnostic {
956960 self
957961 }
958962
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 ( )
961968 }
962969
963970 pub fn set_arg (
964971 & mut self ,
965972 name : impl Into < Cow < ' static , str > > ,
966973 arg : impl IntoDiagnosticArg ,
967974 ) -> & mut Self {
968- self . args . push ( ( name. into ( ) , arg. into_diagnostic_arg ( ) ) ) ;
975+ self . args . insert ( name. into ( ) , arg. into_diagnostic_arg ( ) ) ;
969976 self
970977 }
971978
0 commit comments