Skip to content

Commit 27ed958

Browse files
committed
Rename SubdiagnosticMessage as SubdiagMessage.
1 parent b9fa443 commit 27ed958

File tree

12 files changed

+83
-85
lines changed

12 files changed

+83
-85
lines changed

compiler/rustc_error_messages/src/lib.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ type FluentId = Cow<'static, str>;
256256
/// message so messages of this type must be combined with a `DiagMessage` (using
257257
/// `DiagMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
258258
/// the `Subdiagnostic` derive refer to Fluent identifiers directly.
259-
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
260-
pub enum SubdiagnosticMessage {
259+
#[rustc_diagnostic_item = "SubdiagMessage"]
260+
pub enum SubdiagMessage {
261261
/// Non-translatable diagnostic message.
262262
Str(Cow<'static, str>),
263263
/// Translatable message which has already been translated eagerly.
@@ -278,19 +278,19 @@ pub enum SubdiagnosticMessage {
278278
FluentAttr(FluentId),
279279
}
280280

281-
impl From<String> for SubdiagnosticMessage {
281+
impl From<String> for SubdiagMessage {
282282
fn from(s: String) -> Self {
283-
SubdiagnosticMessage::Str(Cow::Owned(s))
283+
SubdiagMessage::Str(Cow::Owned(s))
284284
}
285285
}
286-
impl From<&'static str> for SubdiagnosticMessage {
286+
impl From<&'static str> for SubdiagMessage {
287287
fn from(s: &'static str) -> Self {
288-
SubdiagnosticMessage::Str(Cow::Borrowed(s))
288+
SubdiagMessage::Str(Cow::Borrowed(s))
289289
}
290290
}
291-
impl From<Cow<'static, str>> for SubdiagnosticMessage {
291+
impl From<Cow<'static, str>> for SubdiagMessage {
292292
fn from(s: Cow<'static, str>) -> Self {
293-
SubdiagnosticMessage::Str(s)
293+
SubdiagMessage::Str(s)
294294
}
295295
}
296296

@@ -319,20 +319,19 @@ pub enum DiagMessage {
319319
}
320320

321321
impl DiagMessage {
322-
/// Given a `SubdiagnosticMessage` which may contain a Fluent attribute, create a new
322+
/// Given a `SubdiagMessage` which may contain a Fluent attribute, create a new
323323
/// `DiagMessage` that combines that attribute with the Fluent identifier of `self`.
324324
///
325-
/// - If the `SubdiagnosticMessage` is non-translatable then return the message as a
326-
/// `DiagMessage`.
325+
/// - If the `SubdiagMessage` is non-translatable then return the message as a `DiagMessage`.
327326
/// - If `self` is non-translatable then return `self`'s message.
328-
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
327+
pub fn with_subdiagnostic_message(&self, sub: SubdiagMessage) -> Self {
329328
let attr = match sub {
330-
SubdiagnosticMessage::Str(s) => return DiagMessage::Str(s),
331-
SubdiagnosticMessage::Translated(s) => return DiagMessage::Translated(s),
332-
SubdiagnosticMessage::FluentIdentifier(id) => {
329+
SubdiagMessage::Str(s) => return DiagMessage::Str(s),
330+
SubdiagMessage::Translated(s) => return DiagMessage::Translated(s),
331+
SubdiagMessage::FluentIdentifier(id) => {
333332
return DiagMessage::FluentIdentifier(id, None);
334333
}
335-
SubdiagnosticMessage::FluentAttr(attr) => attr,
334+
SubdiagMessage::FluentAttr(attr) => attr,
336335
};
337336

338337
match self {
@@ -380,19 +379,19 @@ impl<F: FnOnce() -> String> From<DelayDm<F>> for DiagMessage {
380379
}
381380

382381
/// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but
383-
/// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagnosticMessage` and the
382+
/// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagMessage` and the
384383
/// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be
385384
/// able to convert between these, as much as they'll be converted back into `DiagMessage`
386385
/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive.
387-
impl Into<SubdiagnosticMessage> for DiagMessage {
388-
fn into(self) -> SubdiagnosticMessage {
386+
impl Into<SubdiagMessage> for DiagMessage {
387+
fn into(self) -> SubdiagMessage {
389388
match self {
390-
DiagMessage::Str(s) => SubdiagnosticMessage::Str(s),
391-
DiagMessage::Translated(s) => SubdiagnosticMessage::Translated(s),
392-
DiagMessage::FluentIdentifier(id, None) => SubdiagnosticMessage::FluentIdentifier(id),
389+
DiagMessage::Str(s) => SubdiagMessage::Str(s),
390+
DiagMessage::Translated(s) => SubdiagMessage::Translated(s),
391+
DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::FluentIdentifier(id),
393392
// There isn't really a sensible behaviour for this because it loses information but
394393
// this is the most sensible of the behaviours.
395-
DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagnosticMessage::FluentAttr(attr),
394+
DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagMessage::FluentAttr(attr),
396395
}
397396
}
398397
}

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::snippet::Style;
22
use crate::{
33
CodeSuggestion, DiagCtxt, DiagMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, MultiSpan,
4-
StashKey, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
4+
StashKey, SubdiagMessage, Substitution, SubstitutionPart, SuggestionStyle,
55
};
66
use rustc_data_structures::fx::FxIndexMap;
77
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
@@ -170,8 +170,7 @@ where
170170
);
171171
}
172172

173-
pub trait SubdiagnosticMessageOp<G> =
174-
Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
173+
pub trait SubdiagnosticMessageOp<G> = Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagMessage;
175174

176175
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
177176
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
@@ -377,7 +376,7 @@ impl DiagInner {
377376
// See comment on `Diag::subdiagnostic_message_to_diagnostic_message`.
378377
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
379378
&self,
380-
attr: impl Into<SubdiagnosticMessage>,
379+
attr: impl Into<SubdiagMessage>,
381380
) -> DiagMessage {
382381
let msg =
383382
self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages");
@@ -387,7 +386,7 @@ impl DiagInner {
387386
pub(crate) fn sub(
388387
&mut self,
389388
level: Level,
390-
message: impl Into<SubdiagnosticMessage>,
389+
message: impl Into<SubdiagMessage>,
391390
span: MultiSpan,
392391
) {
393392
let sub = Subdiag {
@@ -604,7 +603,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
604603
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
605604
/// primary.
606605
#[rustc_lint_diagnostics]
607-
pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagnosticMessage>) -> &mut Self {
606+
pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagMessage>) -> &mut Self {
608607
let msg = self.subdiagnostic_message_to_diagnostic_message(label);
609608
self.span.push_span_label(span, msg);
610609
self
@@ -699,7 +698,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
699698
with_fn! { with_note,
700699
/// Add a note attached to this diagnostic.
701700
#[rustc_lint_diagnostics]
702-
pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
701+
pub fn note(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
703702
self.sub(Level::Note, msg, MultiSpan::new());
704703
self
705704
} }
@@ -710,7 +709,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
710709
}
711710

712711
/// This is like [`Diag::note()`], but it's only printed once.
713-
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
712+
pub fn note_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
714713
self.sub(Level::OnceNote, msg, MultiSpan::new());
715714
self
716715
}
@@ -722,7 +721,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
722721
pub fn span_note(
723722
&mut self,
724723
sp: impl Into<MultiSpan>,
725-
msg: impl Into<SubdiagnosticMessage>,
724+
msg: impl Into<SubdiagMessage>,
726725
) -> &mut Self {
727726
self.sub(Level::Note, msg, sp.into());
728727
self
@@ -733,7 +732,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
733732
pub fn span_note_once<S: Into<MultiSpan>>(
734733
&mut self,
735734
sp: S,
736-
msg: impl Into<SubdiagnosticMessage>,
735+
msg: impl Into<SubdiagMessage>,
737736
) -> &mut Self {
738737
self.sub(Level::OnceNote, msg, sp.into());
739738
self
@@ -742,7 +741,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
742741
with_fn! { with_warn,
743742
/// Add a warning attached to this diagnostic.
744743
#[rustc_lint_diagnostics]
745-
pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
744+
pub fn warn(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
746745
self.sub(Level::Warning, msg, MultiSpan::new());
747746
self
748747
} }
@@ -753,7 +752,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
753752
pub fn span_warn<S: Into<MultiSpan>>(
754753
&mut self,
755754
sp: S,
756-
msg: impl Into<SubdiagnosticMessage>,
755+
msg: impl Into<SubdiagMessage>,
757756
) -> &mut Self {
758757
self.sub(Level::Warning, msg, sp.into());
759758
self
@@ -762,13 +761,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
762761
with_fn! { with_help,
763762
/// Add a help message attached to this diagnostic.
764763
#[rustc_lint_diagnostics]
765-
pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
764+
pub fn help(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
766765
self.sub(Level::Help, msg, MultiSpan::new());
767766
self
768767
} }
769768

770769
/// This is like [`Diag::help()`], but it's only printed once.
771-
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
770+
pub fn help_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
772771
self.sub(Level::OnceHelp, msg, MultiSpan::new());
773772
self
774773
}
@@ -785,7 +784,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
785784
pub fn span_help<S: Into<MultiSpan>>(
786785
&mut self,
787786
sp: S,
788-
msg: impl Into<SubdiagnosticMessage>,
787+
msg: impl Into<SubdiagMessage>,
789788
) -> &mut Self {
790789
self.sub(Level::Help, msg, sp.into());
791790
self
@@ -822,7 +821,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
822821
/// In other words, multiple changes need to be applied as part of this suggestion.
823822
pub fn multipart_suggestion(
824823
&mut self,
825-
msg: impl Into<SubdiagnosticMessage>,
824+
msg: impl Into<SubdiagMessage>,
826825
suggestion: Vec<(Span, String)>,
827826
applicability: Applicability,
828827
) -> &mut Self {
@@ -838,7 +837,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
838837
/// In other words, multiple changes need to be applied as part of this suggestion.
839838
pub fn multipart_suggestion_verbose(
840839
&mut self,
841-
msg: impl Into<SubdiagnosticMessage>,
840+
msg: impl Into<SubdiagMessage>,
842841
suggestion: Vec<(Span, String)>,
843842
applicability: Applicability,
844843
) -> &mut Self {
@@ -853,7 +852,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
853852
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
854853
pub fn multipart_suggestion_with_style(
855854
&mut self,
856-
msg: impl Into<SubdiagnosticMessage>,
855+
msg: impl Into<SubdiagMessage>,
857856
mut suggestion: Vec<(Span, String)>,
858857
applicability: Applicability,
859858
style: SuggestionStyle,
@@ -895,7 +894,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
895894
/// improve understandability.
896895
pub fn tool_only_multipart_suggestion(
897896
&mut self,
898-
msg: impl Into<SubdiagnosticMessage>,
897+
msg: impl Into<SubdiagMessage>,
899898
suggestion: Vec<(Span, String)>,
900899
applicability: Applicability,
901900
) -> &mut Self {
@@ -928,7 +927,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
928927
pub fn span_suggestion(
929928
&mut self,
930929
sp: Span,
931-
msg: impl Into<SubdiagnosticMessage>,
930+
msg: impl Into<SubdiagMessage>,
932931
suggestion: impl ToString,
933932
applicability: Applicability,
934933
) -> &mut Self {
@@ -946,7 +945,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
946945
pub fn span_suggestion_with_style(
947946
&mut self,
948947
sp: Span,
949-
msg: impl Into<SubdiagnosticMessage>,
948+
msg: impl Into<SubdiagMessage>,
950949
suggestion: impl ToString,
951950
applicability: Applicability,
952951
style: SuggestionStyle,
@@ -971,7 +970,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
971970
pub fn span_suggestion_verbose(
972971
&mut self,
973972
sp: Span,
974-
msg: impl Into<SubdiagnosticMessage>,
973+
msg: impl Into<SubdiagMessage>,
975974
suggestion: impl ToString,
976975
applicability: Applicability,
977976
) -> &mut Self {
@@ -991,7 +990,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
991990
pub fn span_suggestions(
992991
&mut self,
993992
sp: Span,
994-
msg: impl Into<SubdiagnosticMessage>,
993+
msg: impl Into<SubdiagMessage>,
995994
suggestions: impl IntoIterator<Item = String>,
996995
applicability: Applicability,
997996
) -> &mut Self {
@@ -1007,7 +1006,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10071006
pub fn span_suggestions_with_style(
10081007
&mut self,
10091008
sp: Span,
1010-
msg: impl Into<SubdiagnosticMessage>,
1009+
msg: impl Into<SubdiagMessage>,
10111010
suggestions: impl IntoIterator<Item = String>,
10121011
applicability: Applicability,
10131012
style: SuggestionStyle,
@@ -1036,7 +1035,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10361035
/// See also [`Diag::multipart_suggestion()`].
10371036
pub fn multipart_suggestions(
10381037
&mut self,
1039-
msg: impl Into<SubdiagnosticMessage>,
1038+
msg: impl Into<SubdiagMessage>,
10401039
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
10411040
applicability: Applicability,
10421041
) -> &mut Self {
@@ -1083,7 +1082,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10831082
pub fn span_suggestion_short(
10841083
&mut self,
10851084
sp: Span,
1086-
msg: impl Into<SubdiagnosticMessage>,
1085+
msg: impl Into<SubdiagMessage>,
10871086
suggestion: impl ToString,
10881087
applicability: Applicability,
10891088
) -> &mut Self {
@@ -1106,7 +1105,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11061105
pub fn span_suggestion_hidden(
11071106
&mut self,
11081107
sp: Span,
1109-
msg: impl Into<SubdiagnosticMessage>,
1108+
msg: impl Into<SubdiagMessage>,
11101109
suggestion: impl ToString,
11111110
applicability: Applicability,
11121111
) -> &mut Self {
@@ -1129,7 +1128,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11291128
pub fn tool_only_span_suggestion(
11301129
&mut self,
11311130
sp: Span,
1132-
msg: impl Into<SubdiagnosticMessage>,
1131+
msg: impl Into<SubdiagMessage>,
11331132
suggestion: impl ToString,
11341133
applicability: Applicability,
11351134
) -> &mut Self {
@@ -1200,12 +1199,12 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12001199
self
12011200
} }
12021201

1203-
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagMessage` by
1202+
/// Helper function that takes a `SubdiagMessage` and returns a `DiagMessage` by
12041203
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
12051204
/// passes the user's string along).
12061205
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
12071206
&self,
1208-
attr: impl Into<SubdiagnosticMessage>,
1207+
attr: impl Into<SubdiagMessage>,
12091208
) -> DiagMessage {
12101209
self.deref().subdiagnostic_message_to_diagnostic_message(attr)
12111210
}
@@ -1214,7 +1213,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12141213
/// public methods above.
12151214
///
12161215
/// Used by `proc_macro_server` for implementing `server::Diagnostic`.
1217-
pub fn sub(&mut self, level: Level, message: impl Into<SubdiagnosticMessage>, span: MultiSpan) {
1216+
pub fn sub(&mut self, level: Level, message: impl Into<SubdiagMessage>, span: MultiSpan) {
12181217
self.deref_mut().sub(level, message, span);
12191218
}
12201219

0 commit comments

Comments
 (0)