Skip to content

Commit 1edda0e

Browse files
committed
Rename SubdiagnosticMessage as SubdiagMessage.
1 parent d6ef5c3 commit 1edda0e

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;
@@ -189,8 +189,7 @@ where
189189
);
190190
}
191191

192-
pub trait SubdiagnosticMessageOp<G> =
193-
Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
192+
pub trait SubdiagnosticMessageOp<G> = Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagMessage;
194193

195194
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
196195
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
@@ -396,7 +395,7 @@ impl DiagInner {
396395
// See comment on `Diag::subdiagnostic_message_to_diagnostic_message`.
397396
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
398397
&self,
399-
attr: impl Into<SubdiagnosticMessage>,
398+
attr: impl Into<SubdiagMessage>,
400399
) -> DiagMessage {
401400
let msg =
402401
self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages");
@@ -406,7 +405,7 @@ impl DiagInner {
406405
pub(crate) fn sub(
407406
&mut self,
408407
level: Level,
409-
message: impl Into<SubdiagnosticMessage>,
408+
message: impl Into<SubdiagMessage>,
410409
span: MultiSpan,
411410
) {
412411
let sub = Subdiag {
@@ -623,7 +622,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
623622
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
624623
/// primary.
625624
#[rustc_lint_diagnostics]
626-
pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagnosticMessage>) -> &mut Self {
625+
pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagMessage>) -> &mut Self {
627626
let msg = self.subdiagnostic_message_to_diagnostic_message(label);
628627
self.span.push_span_label(span, msg);
629628
self
@@ -718,7 +717,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
718717
with_fn! { with_note,
719718
/// Add a note attached to this diagnostic.
720719
#[rustc_lint_diagnostics]
721-
pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
720+
pub fn note(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
722721
self.sub(Level::Note, msg, MultiSpan::new());
723722
self
724723
} }
@@ -729,7 +728,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
729728
}
730729

731730
/// This is like [`Diag::note()`], but it's only printed once.
732-
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
731+
pub fn note_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
733732
self.sub(Level::OnceNote, msg, MultiSpan::new());
734733
self
735734
}
@@ -741,7 +740,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
741740
pub fn span_note(
742741
&mut self,
743742
sp: impl Into<MultiSpan>,
744-
msg: impl Into<SubdiagnosticMessage>,
743+
msg: impl Into<SubdiagMessage>,
745744
) -> &mut Self {
746745
self.sub(Level::Note, msg, sp.into());
747746
self
@@ -752,7 +751,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
752751
pub fn span_note_once<S: Into<MultiSpan>>(
753752
&mut self,
754753
sp: S,
755-
msg: impl Into<SubdiagnosticMessage>,
754+
msg: impl Into<SubdiagMessage>,
756755
) -> &mut Self {
757756
self.sub(Level::OnceNote, msg, sp.into());
758757
self
@@ -761,7 +760,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
761760
with_fn! { with_warn,
762761
/// Add a warning attached to this diagnostic.
763762
#[rustc_lint_diagnostics]
764-
pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
763+
pub fn warn(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
765764
self.sub(Level::Warning, msg, MultiSpan::new());
766765
self
767766
} }
@@ -772,7 +771,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
772771
pub fn span_warn<S: Into<MultiSpan>>(
773772
&mut self,
774773
sp: S,
775-
msg: impl Into<SubdiagnosticMessage>,
774+
msg: impl Into<SubdiagMessage>,
776775
) -> &mut Self {
777776
self.sub(Level::Warning, msg, sp.into());
778777
self
@@ -781,13 +780,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
781780
with_fn! { with_help,
782781
/// Add a help message attached to this diagnostic.
783782
#[rustc_lint_diagnostics]
784-
pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
783+
pub fn help(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
785784
self.sub(Level::Help, msg, MultiSpan::new());
786785
self
787786
} }
788787

789788
/// This is like [`Diag::help()`], but it's only printed once.
790-
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
789+
pub fn help_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
791790
self.sub(Level::OnceHelp, msg, MultiSpan::new());
792791
self
793792
}
@@ -804,7 +803,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
804803
pub fn span_help<S: Into<MultiSpan>>(
805804
&mut self,
806805
sp: S,
807-
msg: impl Into<SubdiagnosticMessage>,
806+
msg: impl Into<SubdiagMessage>,
808807
) -> &mut Self {
809808
self.sub(Level::Help, msg, sp.into());
810809
self
@@ -841,7 +840,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
841840
/// In other words, multiple changes need to be applied as part of this suggestion.
842841
pub fn multipart_suggestion(
843842
&mut self,
844-
msg: impl Into<SubdiagnosticMessage>,
843+
msg: impl Into<SubdiagMessage>,
845844
suggestion: Vec<(Span, String)>,
846845
applicability: Applicability,
847846
) -> &mut Self {
@@ -857,7 +856,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
857856
/// In other words, multiple changes need to be applied as part of this suggestion.
858857
pub fn multipart_suggestion_verbose(
859858
&mut self,
860-
msg: impl Into<SubdiagnosticMessage>,
859+
msg: impl Into<SubdiagMessage>,
861860
suggestion: Vec<(Span, String)>,
862861
applicability: Applicability,
863862
) -> &mut Self {
@@ -872,7 +871,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
872871
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
873872
pub fn multipart_suggestion_with_style(
874873
&mut self,
875-
msg: impl Into<SubdiagnosticMessage>,
874+
msg: impl Into<SubdiagMessage>,
876875
mut suggestion: Vec<(Span, String)>,
877876
applicability: Applicability,
878877
style: SuggestionStyle,
@@ -914,7 +913,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
914913
/// improve understandability.
915914
pub fn tool_only_multipart_suggestion(
916915
&mut self,
917-
msg: impl Into<SubdiagnosticMessage>,
916+
msg: impl Into<SubdiagMessage>,
918917
suggestion: Vec<(Span, String)>,
919918
applicability: Applicability,
920919
) -> &mut Self {
@@ -947,7 +946,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
947946
pub fn span_suggestion(
948947
&mut self,
949948
sp: Span,
950-
msg: impl Into<SubdiagnosticMessage>,
949+
msg: impl Into<SubdiagMessage>,
951950
suggestion: impl ToString,
952951
applicability: Applicability,
953952
) -> &mut Self {
@@ -965,7 +964,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
965964
pub fn span_suggestion_with_style(
966965
&mut self,
967966
sp: Span,
968-
msg: impl Into<SubdiagnosticMessage>,
967+
msg: impl Into<SubdiagMessage>,
969968
suggestion: impl ToString,
970969
applicability: Applicability,
971970
style: SuggestionStyle,
@@ -990,7 +989,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
990989
pub fn span_suggestion_verbose(
991990
&mut self,
992991
sp: Span,
993-
msg: impl Into<SubdiagnosticMessage>,
992+
msg: impl Into<SubdiagMessage>,
994993
suggestion: impl ToString,
995994
applicability: Applicability,
996995
) -> &mut Self {
@@ -1010,7 +1009,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10101009
pub fn span_suggestions(
10111010
&mut self,
10121011
sp: Span,
1013-
msg: impl Into<SubdiagnosticMessage>,
1012+
msg: impl Into<SubdiagMessage>,
10141013
suggestions: impl IntoIterator<Item = String>,
10151014
applicability: Applicability,
10161015
) -> &mut Self {
@@ -1026,7 +1025,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10261025
pub fn span_suggestions_with_style(
10271026
&mut self,
10281027
sp: Span,
1029-
msg: impl Into<SubdiagnosticMessage>,
1028+
msg: impl Into<SubdiagMessage>,
10301029
suggestions: impl IntoIterator<Item = String>,
10311030
applicability: Applicability,
10321031
style: SuggestionStyle,
@@ -1055,7 +1054,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10551054
/// See also [`Diag::multipart_suggestion()`].
10561055
pub fn multipart_suggestions(
10571056
&mut self,
1058-
msg: impl Into<SubdiagnosticMessage>,
1057+
msg: impl Into<SubdiagMessage>,
10591058
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
10601059
applicability: Applicability,
10611060
) -> &mut Self {
@@ -1102,7 +1101,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11021101
pub fn span_suggestion_short(
11031102
&mut self,
11041103
sp: Span,
1105-
msg: impl Into<SubdiagnosticMessage>,
1104+
msg: impl Into<SubdiagMessage>,
11061105
suggestion: impl ToString,
11071106
applicability: Applicability,
11081107
) -> &mut Self {
@@ -1125,7 +1124,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11251124
pub fn span_suggestion_hidden(
11261125
&mut self,
11271126
sp: Span,
1128-
msg: impl Into<SubdiagnosticMessage>,
1127+
msg: impl Into<SubdiagMessage>,
11291128
suggestion: impl ToString,
11301129
applicability: Applicability,
11311130
) -> &mut Self {
@@ -1148,7 +1147,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11481147
pub fn tool_only_span_suggestion(
11491148
&mut self,
11501149
sp: Span,
1151-
msg: impl Into<SubdiagnosticMessage>,
1150+
msg: impl Into<SubdiagMessage>,
11521151
suggestion: impl ToString,
11531152
applicability: Applicability,
11541153
) -> &mut Self {
@@ -1219,12 +1218,12 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12191218
self
12201219
} }
12211220

1222-
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagMessage` by
1221+
/// Helper function that takes a `SubdiagMessage` and returns a `DiagMessage` by
12231222
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
12241223
/// passes the user's string along).
12251224
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
12261225
&self,
1227-
attr: impl Into<SubdiagnosticMessage>,
1226+
attr: impl Into<SubdiagMessage>,
12281227
) -> DiagMessage {
12291228
self.deref().subdiagnostic_message_to_diagnostic_message(attr)
12301229
}
@@ -1233,7 +1232,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12331232
/// public methods above.
12341233
///
12351234
/// Used by `proc_macro_server` for implementing `server::Diagnostic`.
1236-
pub fn sub(&mut self, level: Level, message: impl Into<SubdiagnosticMessage>, span: MultiSpan) {
1235+
pub fn sub(&mut self, level: Level, message: impl Into<SubdiagMessage>, span: MultiSpan) {
12371236
self.deref_mut().sub(level, message, span);
12381237
}
12391238

0 commit comments

Comments
 (0)