Skip to content

Commit f6def91

Browse files
committed
Rename DiagnosticMessage as DiagMessage.
1 parent 1a1876c commit f6def91

File tree

49 files changed

+253
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+253
-261
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::emitter::Emitter;
1717
use rustc_errors::translation::Translate;
1818
use rustc_errors::{
19-
Diag, DiagArgMap, DiagCtxt, DiagnosticMessage, ErrCode, FatalError, FluentBundle, Level,
20-
MultiSpan, Style,
19+
Diag, DiagArgMap, DiagCtxt, DiagMessage, ErrCode, FatalError, FluentBundle, Level, MultiSpan,
20+
Style,
2121
};
2222
use rustc_fs_util::link_or_copy;
2323
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
@@ -1010,7 +1010,7 @@ pub struct CguMessage;
10101010
// - `emitted_at`: not used for codegen diagnostics.
10111011
struct Diagnostic {
10121012
level: Level,
1013-
messages: Vec<(DiagnosticMessage, Style)>,
1013+
messages: Vec<(DiagMessage, Style)>,
10141014
code: Option<ErrCode>,
10151015
children: Vec<Subdiagnostic>,
10161016
args: DiagArgMap,
@@ -1021,7 +1021,7 @@ struct Diagnostic {
10211021
// - `span`: it doesn't impl `Send`.
10221022
pub struct Subdiagnostic {
10231023
level: Level,
1024-
messages: Vec<(DiagnosticMessage, Style)>,
1024+
messages: Vec<(DiagMessage, Style)>,
10251025
}
10261026

10271027
#[derive(PartialEq, Clone, Copy, Debug)]

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::mem;
22

3-
use rustc_errors::{
4-
DiagArgName, DiagArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg,
5-
};
3+
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, IntoDiagnostic, IntoDiagnosticArg};
64
use rustc_hir::CRATE_HIR_ID;
75
use rustc_middle::mir::AssertKind;
86
use rustc_middle::query::TyCtxtAt;
@@ -25,7 +23,7 @@ pub enum ConstEvalErrKind {
2523
}
2624

2725
impl MachineStopType for ConstEvalErrKind {
28-
fn diagnostic_message(&self) -> DiagnosticMessage {
26+
fn diagnostic_message(&self) -> DiagMessage {
2927
use crate::fluent_generated::*;
3028
use ConstEvalErrKind::*;
3129
match self {

compiler/rustc_const_eval/src/errors.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::borrow::Cow;
22

33
use rustc_errors::{
4-
codes::*, Diag, DiagArgValue, DiagCtxt, DiagnosticMessage, EmissionGuarantee, IntoDiagnostic,
5-
Level,
4+
codes::*, Diag, DiagArgValue, DiagCtxt, DiagMessage, EmissionGuarantee, IntoDiagnostic, Level,
65
};
76
use rustc_hir::ConstContext;
87
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@@ -424,7 +423,7 @@ pub struct UndefinedBehavior {
424423

425424
pub trait ReportErrorExt {
426425
/// Returns the diagnostic message for this error.
427-
fn diagnostic_message(&self) -> DiagnosticMessage;
426+
fn diagnostic_message(&self) -> DiagMessage;
428427
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>);
429428

430429
fn debug(self) -> String
@@ -433,7 +432,7 @@ pub trait ReportErrorExt {
433432
{
434433
ty::tls::with(move |tcx| {
435434
let dcx = tcx.dcx();
436-
let mut diag = dcx.struct_allow(DiagnosticMessage::Str(String::new().into()));
435+
let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into()));
437436
let message = self.diagnostic_message();
438437
self.add_args(&mut diag);
439438
let s = dcx.eagerly_translate_to_string(message, diag.args.iter());
@@ -457,7 +456,7 @@ fn bad_pointer_message(msg: CheckInAllocMsg, dcx: &DiagCtxt) -> String {
457456
}
458457

459458
impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
460-
fn diagnostic_message(&self) -> DiagnosticMessage {
459+
fn diagnostic_message(&self) -> DiagMessage {
461460
use crate::fluent_generated::*;
462461
use UndefinedBehaviorInfo::*;
463462
match self {
@@ -595,7 +594,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
595594
}
596595

597596
impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
598-
fn diagnostic_message(&self) -> DiagnosticMessage {
597+
fn diagnostic_message(&self) -> DiagMessage {
599598
use crate::fluent_generated::*;
600599
use rustc_middle::mir::interpret::ValidationErrorKind::*;
601600
match self.kind {
@@ -785,7 +784,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
785784
}
786785

787786
impl ReportErrorExt for UnsupportedOpInfo {
788-
fn diagnostic_message(&self) -> DiagnosticMessage {
787+
fn diagnostic_message(&self) -> DiagMessage {
789788
use crate::fluent_generated::*;
790789
match self {
791790
UnsupportedOpInfo::Unsupported(s) => s.clone().into(),
@@ -821,7 +820,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
821820
}
822821

823822
impl<'tcx> ReportErrorExt for InterpError<'tcx> {
824-
fn diagnostic_message(&self) -> DiagnosticMessage {
823+
fn diagnostic_message(&self) -> DiagMessage {
825824
match self {
826825
InterpError::UndefinedBehavior(ub) => ub.diagnostic_message(),
827826
InterpError::Unsupported(e) => e.diagnostic_message(),
@@ -844,7 +843,7 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> {
844843
}
845844

846845
impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
847-
fn diagnostic_message(&self) -> DiagnosticMessage {
846+
fn diagnostic_message(&self) -> DiagMessage {
848847
use crate::fluent_generated::*;
849848
match self {
850849
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
@@ -879,7 +878,7 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
879878
}
880879

881880
impl ReportErrorExt for ResourceExhaustionInfo {
882-
fn diagnostic_message(&self) -> DiagnosticMessage {
881+
fn diagnostic_message(&self) -> DiagMessage {
883882
use crate::fluent_generated::*;
884883
match self {
885884
ResourceExhaustionInfo::StackFrameLimitReached => const_eval_stack_frame_limit_reached,

compiler/rustc_error_messages/src/lib.rs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ type FluentId = Cow<'static, str>;
253253
/// translatable and non-translatable diagnostic messages.
254254
///
255255
/// 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
258258
/// the `Subdiagnostic` derive refer to Fluent identifiers directly.
259259
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
260260
pub enum SubdiagnosticMessage {
@@ -265,7 +265,7 @@ pub enum SubdiagnosticMessage {
265265
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
266266
/// be instantiated multiple times with different values. These subdiagnostics' messages
267267
/// are translated when they are added to the parent diagnostic, producing this variant of
268-
/// `DiagnosticMessage`.
268+
/// `DiagMessage`.
269269
Translated(Cow<'static, str>),
270270
/// Identifier of a Fluent message. Instances of this variant are generated by the
271271
/// `Subdiagnostic` derive.
@@ -299,16 +299,16 @@ impl From<Cow<'static, str>> for SubdiagnosticMessage {
299299
///
300300
/// Intended to be removed once diagnostics are entirely translatable.
301301
#[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 {
304304
/// Non-translatable diagnostic message.
305305
Str(Cow<'static, str>),
306306
/// Translatable message which has been already translated.
307307
///
308308
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
309309
/// be instantiated multiple times with different values. These subdiagnostics' messages
310310
/// are translated when they are added to the parent diagnostic, producing this variant of
311-
/// `DiagnosticMessage`.
311+
/// `DiagMessage`.
312312
Translated(Cow<'static, str>),
313313
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
314314
/// message. Yet to be translated.
@@ -318,85 +318,81 @@ pub enum DiagnosticMessage {
318318
FluentIdentifier(FluentId, Option<FluentId>),
319319
}
320320

321-
impl DiagnosticMessage {
321+
impl DiagMessage {
322322
/// 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`.
324324
///
325325
/// - If the `SubdiagnosticMessage` is non-translatable then return the message as a
326-
/// `DiagnosticMessage`.
326+
/// `DiagMessage`.
327327
/// - If `self` is non-translatable then return `self`'s message.
328328
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
329329
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),
332332
SubdiagnosticMessage::FluentIdentifier(id) => {
333-
return DiagnosticMessage::FluentIdentifier(id, None);
333+
return DiagMessage::FluentIdentifier(id, None);
334334
}
335335
SubdiagnosticMessage::FluentAttr(attr) => attr,
336336
};
337337

338338
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))
343343
}
344344
}
345345
}
346346

347347
pub fn as_str(&self) -> Option<&str> {
348348
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,
351351
}
352352
}
353353
}
354354

355-
impl From<String> for DiagnosticMessage {
355+
impl From<String> for DiagMessage {
356356
fn from(s: String) -> Self {
357-
DiagnosticMessage::Str(Cow::Owned(s))
357+
DiagMessage::Str(Cow::Owned(s))
358358
}
359359
}
360-
impl From<&'static str> for DiagnosticMessage {
360+
impl From<&'static str> for DiagMessage {
361361
fn from(s: &'static str) -> Self {
362-
DiagnosticMessage::Str(Cow::Borrowed(s))
362+
DiagMessage::Str(Cow::Borrowed(s))
363363
}
364364
}
365-
impl From<Cow<'static, str>> for DiagnosticMessage {
365+
impl From<Cow<'static, str>> for DiagMessage {
366366
fn from(s: Cow<'static, str>) -> Self {
367-
DiagnosticMessage::Str(s)
367+
DiagMessage::Str(s)
368368
}
369369
}
370370

371371
/// A workaround for must_produce_diag ICEs when formatting types in disabled lints.
372372
///
373-
/// Delays formatting until `.into(): DiagnosticMessage` is used.
373+
/// Delays formatting until `.into(): DiagMessage` is used.
374374
pub struct DelayDm<F>(pub F);
375375

376-
impl<F: FnOnce() -> String> From<DelayDm<F>> for DiagnosticMessage {
376+
impl<F: FnOnce() -> String> From<DelayDm<F>> for DiagMessage {
377377
fn from(DelayDm(f): DelayDm<F>) -> Self {
378-
DiagnosticMessage::from(f())
378+
DiagMessage::from(f())
379379
}
380380
}
381381

382382
/// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but
383383
/// 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`
386386
/// 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 {
388388
fn into(self) -> SubdiagnosticMessage {
389389
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),
395393
// There isn't really a sensible behaviour for this because it loses information but
396394
// 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),
400396
}
401397
}
402398
}
@@ -412,7 +408,7 @@ pub struct SpanLabel {
412408
pub is_primary: bool,
413409

414410
/// What label should we attach to this span (if any)?
415-
pub label: Option<DiagnosticMessage>,
411+
pub label: Option<DiagMessage>,
416412
}
417413

418414
/// A collection of `Span`s.
@@ -426,7 +422,7 @@ pub struct SpanLabel {
426422
#[derive(Clone, Debug, Hash, PartialEq, Eq, Encodable, Decodable)]
427423
pub struct MultiSpan {
428424
primary_spans: Vec<Span>,
429-
span_labels: Vec<(Span, DiagnosticMessage)>,
425+
span_labels: Vec<(Span, DiagMessage)>,
430426
}
431427

432428
impl MultiSpan {
@@ -444,7 +440,7 @@ impl MultiSpan {
444440
MultiSpan { primary_spans: vec, span_labels: vec![] }
445441
}
446442

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>) {
448444
self.span_labels.push((span, label.into()));
449445
}
450446

@@ -487,7 +483,7 @@ impl MultiSpan {
487483
replacements_occurred
488484
}
489485

490-
pub fn pop_span_label(&mut self) -> Option<(Span, DiagnosticMessage)> {
486+
pub fn pop_span_label(&mut self) -> Option<(Span, DiagMessage)> {
491487
self.span_labels.pop()
492488
}
493489

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::emitter::FileWithAnnotatedLines;
99
use crate::snippet::Line;
1010
use crate::translation::{to_fluent_args, Translate};
1111
use crate::{
12-
CodeSuggestion, DiagInner, DiagnosticMessage, Emitter, ErrCode, FluentBundle,
13-
LazyFallbackBundle, Level, MultiSpan, Style, Subdiag,
12+
CodeSuggestion, DiagInner, DiagMessage, Emitter, ErrCode, FluentBundle, LazyFallbackBundle,
13+
Level, MultiSpan, Style, Subdiag,
1414
};
1515
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
1616
use rustc_data_structures::sync::Lrc;
@@ -125,7 +125,7 @@ impl AnnotateSnippetEmitter {
125125
fn emit_messages_default(
126126
&mut self,
127127
level: &Level,
128-
messages: &[(DiagnosticMessage, Style)],
128+
messages: &[(DiagMessage, Style)],
129129
args: &FluentArgs<'_>,
130130
code: &Option<ErrCode>,
131131
msp: &MultiSpan,

0 commit comments

Comments
 (0)