@@ -253,8 +253,8 @@ type FluentId = Cow<'static, str>;
253
253
/// translatable and non-translatable diagnostic messages.
254
254
///
255
255
/// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent
256
- /// message so messages of this type must be combined with a `DiagnosticMessage ` (using
257
- /// `DiagnosticMessage ::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
256
+ /// message so messages of this type must be combined with a `DiagMessage ` (using
257
+ /// `DiagMessage ::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
258
258
/// the `Subdiagnostic` derive refer to Fluent identifiers directly.
259
259
#[ rustc_diagnostic_item = "SubdiagnosticMessage" ]
260
260
pub enum SubdiagnosticMessage {
@@ -265,7 +265,7 @@ pub enum SubdiagnosticMessage {
265
265
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
266
266
/// be instantiated multiple times with different values. These subdiagnostics' messages
267
267
/// are translated when they are added to the parent diagnostic, producing this variant of
268
- /// `DiagnosticMessage `.
268
+ /// `DiagMessage `.
269
269
Translated ( Cow < ' static , str > ) ,
270
270
/// Identifier of a Fluent message. Instances of this variant are generated by the
271
271
/// `Subdiagnostic` derive.
@@ -299,16 +299,16 @@ impl From<Cow<'static, str>> for SubdiagnosticMessage {
299
299
///
300
300
/// Intended to be removed once diagnostics are entirely translatable.
301
301
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Encodable , Decodable ) ]
302
- #[ rustc_diagnostic_item = "DiagnosticMessage " ]
303
- pub enum DiagnosticMessage {
302
+ #[ rustc_diagnostic_item = "DiagMessage " ]
303
+ pub enum DiagMessage {
304
304
/// Non-translatable diagnostic message.
305
305
Str ( Cow < ' static , str > ) ,
306
306
/// Translatable message which has been already translated.
307
307
///
308
308
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
309
309
/// be instantiated multiple times with different values. These subdiagnostics' messages
310
310
/// are translated when they are added to the parent diagnostic, producing this variant of
311
- /// `DiagnosticMessage `.
311
+ /// `DiagMessage `.
312
312
Translated ( Cow < ' static , str > ) ,
313
313
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
314
314
/// message. Yet to be translated.
@@ -318,85 +318,81 @@ pub enum DiagnosticMessage {
318
318
FluentIdentifier ( FluentId , Option < FluentId > ) ,
319
319
}
320
320
321
- impl DiagnosticMessage {
321
+ impl DiagMessage {
322
322
/// Given a `SubdiagnosticMessage` which may contain a Fluent attribute, create a new
323
- /// `DiagnosticMessage ` that combines that attribute with the Fluent identifier of `self`.
323
+ /// `DiagMessage ` that combines that attribute with the Fluent identifier of `self`.
324
324
///
325
325
/// - If the `SubdiagnosticMessage` is non-translatable then return the message as a
326
- /// `DiagnosticMessage `.
326
+ /// `DiagMessage `.
327
327
/// - If `self` is non-translatable then return `self`'s message.
328
328
pub fn with_subdiagnostic_message ( & self , sub : SubdiagnosticMessage ) -> Self {
329
329
let attr = match sub {
330
- SubdiagnosticMessage :: Str ( s) => return DiagnosticMessage :: Str ( s) ,
331
- SubdiagnosticMessage :: Translated ( s) => return DiagnosticMessage :: Translated ( s) ,
330
+ SubdiagnosticMessage :: Str ( s) => return DiagMessage :: Str ( s) ,
331
+ SubdiagnosticMessage :: Translated ( s) => return DiagMessage :: Translated ( s) ,
332
332
SubdiagnosticMessage :: FluentIdentifier ( id) => {
333
- return DiagnosticMessage :: FluentIdentifier ( id, None ) ;
333
+ return DiagMessage :: FluentIdentifier ( id, None ) ;
334
334
}
335
335
SubdiagnosticMessage :: FluentAttr ( attr) => attr,
336
336
} ;
337
337
338
338
match self {
339
- DiagnosticMessage :: Str ( s) => DiagnosticMessage :: Str ( s. clone ( ) ) ,
340
- DiagnosticMessage :: Translated ( s) => DiagnosticMessage :: Translated ( s. clone ( ) ) ,
341
- DiagnosticMessage :: FluentIdentifier ( id, _) => {
342
- DiagnosticMessage :: FluentIdentifier ( id. clone ( ) , Some ( attr) )
339
+ DiagMessage :: Str ( s) => DiagMessage :: Str ( s. clone ( ) ) ,
340
+ DiagMessage :: Translated ( s) => DiagMessage :: Translated ( s. clone ( ) ) ,
341
+ DiagMessage :: FluentIdentifier ( id, _) => {
342
+ DiagMessage :: FluentIdentifier ( id. clone ( ) , Some ( attr) )
343
343
}
344
344
}
345
345
}
346
346
347
347
pub fn as_str ( & self ) -> Option < & str > {
348
348
match self {
349
- DiagnosticMessage :: Translated ( s) | DiagnosticMessage :: Str ( s) => Some ( s) ,
350
- DiagnosticMessage :: FluentIdentifier ( _, _) => None ,
349
+ DiagMessage :: Translated ( s) | DiagMessage :: Str ( s) => Some ( s) ,
350
+ DiagMessage :: FluentIdentifier ( _, _) => None ,
351
351
}
352
352
}
353
353
}
354
354
355
- impl From < String > for DiagnosticMessage {
355
+ impl From < String > for DiagMessage {
356
356
fn from ( s : String ) -> Self {
357
- DiagnosticMessage :: Str ( Cow :: Owned ( s) )
357
+ DiagMessage :: Str ( Cow :: Owned ( s) )
358
358
}
359
359
}
360
- impl From < & ' static str > for DiagnosticMessage {
360
+ impl From < & ' static str > for DiagMessage {
361
361
fn from ( s : & ' static str ) -> Self {
362
- DiagnosticMessage :: Str ( Cow :: Borrowed ( s) )
362
+ DiagMessage :: Str ( Cow :: Borrowed ( s) )
363
363
}
364
364
}
365
- impl From < Cow < ' static , str > > for DiagnosticMessage {
365
+ impl From < Cow < ' static , str > > for DiagMessage {
366
366
fn from ( s : Cow < ' static , str > ) -> Self {
367
- DiagnosticMessage :: Str ( s)
367
+ DiagMessage :: Str ( s)
368
368
}
369
369
}
370
370
371
371
/// A workaround for must_produce_diag ICEs when formatting types in disabled lints.
372
372
///
373
- /// Delays formatting until `.into(): DiagnosticMessage ` is used.
373
+ /// Delays formatting until `.into(): DiagMessage ` is used.
374
374
pub struct DelayDm < F > ( pub F ) ;
375
375
376
- impl < F : FnOnce ( ) -> String > From < DelayDm < F > > for DiagnosticMessage {
376
+ impl < F : FnOnce ( ) -> String > From < DelayDm < F > > for DiagMessage {
377
377
fn from ( DelayDm ( f) : DelayDm < F > ) -> Self {
378
- DiagnosticMessage :: from ( f ( ) )
378
+ DiagMessage :: from ( f ( ) )
379
379
}
380
380
}
381
381
382
382
/// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but
383
383
/// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagnosticMessage` and the
384
- /// subdiagnostic derive refers to typed identifiers that are `DiagnosticMessage `s, so need to be
385
- /// able to convert between these, as much as they'll be converted back into `DiagnosticMessage `
384
+ /// subdiagnostic derive refers to typed identifiers that are `DiagMessage `s, so need to be
385
+ /// able to convert between these, as much as they'll be converted back into `DiagMessage `
386
386
/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive.
387
- impl Into < SubdiagnosticMessage > for DiagnosticMessage {
387
+ impl Into < SubdiagnosticMessage > for DiagMessage {
388
388
fn into ( self ) -> SubdiagnosticMessage {
389
389
match self {
390
- DiagnosticMessage :: Str ( s) => SubdiagnosticMessage :: Str ( s) ,
391
- DiagnosticMessage :: Translated ( s) => SubdiagnosticMessage :: Translated ( s) ,
392
- DiagnosticMessage :: FluentIdentifier ( id, None ) => {
393
- SubdiagnosticMessage :: FluentIdentifier ( id)
394
- }
390
+ DiagMessage :: Str ( s) => SubdiagnosticMessage :: Str ( s) ,
391
+ DiagMessage :: Translated ( s) => SubdiagnosticMessage :: Translated ( s) ,
392
+ DiagMessage :: FluentIdentifier ( id, None ) => SubdiagnosticMessage :: FluentIdentifier ( id) ,
395
393
// There isn't really a sensible behaviour for this because it loses information but
396
394
// this is the most sensible of the behaviours.
397
- DiagnosticMessage :: FluentIdentifier ( _, Some ( attr) ) => {
398
- SubdiagnosticMessage :: FluentAttr ( attr)
399
- }
395
+ DiagMessage :: FluentIdentifier ( _, Some ( attr) ) => SubdiagnosticMessage :: FluentAttr ( attr) ,
400
396
}
401
397
}
402
398
}
@@ -412,7 +408,7 @@ pub struct SpanLabel {
412
408
pub is_primary : bool ,
413
409
414
410
/// What label should we attach to this span (if any)?
415
- pub label : Option < DiagnosticMessage > ,
411
+ pub label : Option < DiagMessage > ,
416
412
}
417
413
418
414
/// A collection of `Span`s.
@@ -426,7 +422,7 @@ pub struct SpanLabel {
426
422
#[ derive( Clone , Debug , Hash , PartialEq , Eq , Encodable , Decodable ) ]
427
423
pub struct MultiSpan {
428
424
primary_spans : Vec < Span > ,
429
- span_labels : Vec < ( Span , DiagnosticMessage ) > ,
425
+ span_labels : Vec < ( Span , DiagMessage ) > ,
430
426
}
431
427
432
428
impl MultiSpan {
@@ -444,7 +440,7 @@ impl MultiSpan {
444
440
MultiSpan { primary_spans : vec, span_labels : vec ! [ ] }
445
441
}
446
442
447
- pub fn push_span_label ( & mut self , span : Span , label : impl Into < DiagnosticMessage > ) {
443
+ pub fn push_span_label ( & mut self , span : Span , label : impl Into < DiagMessage > ) {
448
444
self . span_labels . push ( ( span, label. into ( ) ) ) ;
449
445
}
450
446
@@ -487,7 +483,7 @@ impl MultiSpan {
487
483
replacements_occurred
488
484
}
489
485
490
- pub fn pop_span_label ( & mut self ) -> Option < ( Span , DiagnosticMessage ) > {
486
+ pub fn pop_span_label ( & mut self ) -> Option < ( Span , DiagMessage ) > {
491
487
self . span_labels . pop ( )
492
488
}
493
489
0 commit comments