Improve some names.

Lots of vectors of messages called `message` or `msg`. This commit
pluralizes them.

Note that `emit_message_default` and `emit_messages_default` both
already existed, and both process a vector, so I renamed the former
`emit_messages_default_inner` because it's called by the latter.
This commit is contained in:
Nicholas Nethercote 2023-12-20 17:12:17 +11:00
parent d7a3b6291c
commit 824667f753
12 changed files with 45 additions and 45 deletions

View File

@ -102,7 +102,7 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> { impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level); let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message"); let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args()); let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
let mut diag = let mut diag =

View File

@ -986,7 +986,7 @@ pub(crate) enum Message<B: WriteBackendMethods> {
type DiagnosticArgName<'source> = Cow<'source, str>; type DiagnosticArgName<'source> = Cow<'source, str>;
struct Diagnostic { struct Diagnostic {
msg: Vec<(DiagnosticMessage, Style)>, msgs: Vec<(DiagnosticMessage, Style)>,
args: FxHashMap<DiagnosticArgName<'static>, rustc_errors::DiagnosticArgValue<'static>>, args: FxHashMap<DiagnosticArgName<'static>, rustc_errors::DiagnosticArgValue<'static>>,
code: Option<DiagnosticId>, code: Option<DiagnosticId>,
lvl: Level, lvl: Level,
@ -1799,14 +1799,14 @@ fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
let args: FxHashMap<Cow<'_, str>, rustc_errors::DiagnosticArgValue<'_>> = let args: FxHashMap<Cow<'_, str>, rustc_errors::DiagnosticArgValue<'_>> =
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect(); diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msg: diag.message.clone(), msgs: diag.messages.clone(),
args: args.clone(), args: args.clone(),
code: diag.code.clone(), code: diag.code.clone(),
lvl: diag.level(), lvl: diag.level(),
}))); })));
for child in &diag.children { for child in &diag.children {
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msg: child.message.clone(), msgs: child.messages.clone(),
args: args.clone(), args: args.clone(),
code: None, code: None,
lvl: child.level, lvl: child.level,
@ -1838,7 +1838,7 @@ pub fn check(&self, sess: &Session, blocking: bool) {
match message { match message {
Ok(SharedEmitterMessage::Diagnostic(diag)) => { Ok(SharedEmitterMessage::Diagnostic(diag)) => {
let dcx = sess.dcx(); let dcx = sess.dcx();
let mut d = rustc_errors::Diagnostic::new_with_messages(diag.lvl, diag.msg); let mut d = rustc_errors::Diagnostic::new_with_messages(diag.lvl, diag.msgs);
if let Some(code) = diag.code { if let Some(code) = diag.code {
d.code(code); d.code(code);
} }

View File

@ -60,7 +60,7 @@ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
self.emit_messages_default( self.emit_messages_default(
&diag.level, &diag.level,
&diag.message, &diag.messages,
&fluent_args, &fluent_args,
&diag.code, &diag.code,
&primary_span, &primary_span,

View File

@ -103,7 +103,7 @@ pub struct Diagnostic {
// outside of what methods in this crate themselves allow. // outside of what methods in this crate themselves allow.
pub(crate) level: Level, pub(crate) level: Level,
pub message: Vec<(DiagnosticMessage, Style)>, pub messages: Vec<(DiagnosticMessage, Style)>,
pub code: Option<DiagnosticId>, pub code: Option<DiagnosticId>,
pub span: MultiSpan, pub span: MultiSpan,
pub children: Vec<SubDiagnostic>, pub children: Vec<SubDiagnostic>,
@ -161,7 +161,7 @@ pub enum DiagnosticId {
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
pub struct SubDiagnostic { pub struct SubDiagnostic {
pub level: Level, pub level: Level,
pub message: Vec<(DiagnosticMessage, Style)>, pub messages: Vec<(DiagnosticMessage, Style)>,
pub span: MultiSpan, pub span: MultiSpan,
pub render_span: Option<MultiSpan>, pub render_span: Option<MultiSpan>,
} }
@ -223,7 +223,7 @@ pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self { pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self {
Diagnostic { Diagnostic {
level, level,
message: messages, messages,
code: None, code: None,
span: MultiSpan::new(), span: MultiSpan::new(),
children: vec![], children: vec![],
@ -905,7 +905,7 @@ pub fn get_code(&self) -> Option<DiagnosticId> {
} }
pub fn set_primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self { pub fn set_primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
self.message[0] = (msg.into(), Style::NoStyle); self.messages[0] = (msg.into(), Style::NoStyle);
self self
} }
@ -932,8 +932,8 @@ pub fn replace_args(
self.args = args; self.args = args;
} }
pub fn styled_message(&self) -> &[(DiagnosticMessage, Style)] { pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
&self.message &self.messages
} }
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by /// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
@ -944,7 +944,7 @@ fn subdiagnostic_message_to_diagnostic_message(
attr: impl Into<SubdiagnosticMessage>, attr: impl Into<SubdiagnosticMessage>,
) -> DiagnosticMessage { ) -> DiagnosticMessage {
let msg = let msg =
self.message.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages"); self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages");
msg.with_subdiagnostic_message(attr.into()) msg.with_subdiagnostic_message(attr.into())
} }
@ -961,7 +961,7 @@ pub fn sub(
) { ) {
let sub = SubDiagnostic { let sub = SubDiagnostic {
level, level,
message: vec![( messages: vec![(
self.subdiagnostic_message_to_diagnostic_message(message), self.subdiagnostic_message_to_diagnostic_message(message),
Style::NoStyle, Style::NoStyle,
)], )],
@ -976,15 +976,15 @@ pub fn sub(
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>( fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
&mut self, &mut self,
level: Level, level: Level,
message: Vec<(M, Style)>, messages: Vec<(M, Style)>,
span: MultiSpan, span: MultiSpan,
render_span: Option<MultiSpan>, render_span: Option<MultiSpan>,
) { ) {
let message = message let messages = messages
.into_iter() .into_iter()
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1)) .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
.collect(); .collect();
let sub = SubDiagnostic { level, message, span, render_span }; let sub = SubDiagnostic { level, messages, span, render_span };
self.children.push(sub); self.children.push(sub);
} }
@ -1002,7 +1002,7 @@ fn keys(
) { ) {
( (
&self.level, &self.level,
&self.message, &self.messages,
self.args().collect(), self.args().collect(),
&self.code, &self.code,
&self.span, &self.span,

View File

@ -350,7 +350,7 @@ fn fix_multispans_in_extern_macros_and_render_macro_backtrace(
children.push(SubDiagnostic { children.push(SubDiagnostic {
level: Level::Note, level: Level::Note,
message: vec![(DiagnosticMessage::from(msg), Style::NoStyle)], messages: vec![(DiagnosticMessage::from(msg), Style::NoStyle)],
span: MultiSpan::new(), span: MultiSpan::new(),
render_span: None, render_span: None,
}); });
@ -533,7 +533,7 @@ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
self.emit_messages_default( self.emit_messages_default(
&diag.level, &diag.level,
&diag.message, &diag.messages,
&fluent_args, &fluent_args,
&diag.code, &diag.code,
&primary_span, &primary_span,
@ -1228,10 +1228,10 @@ fn get_max_line_num(&mut self, span: &MultiSpan, children: &[SubDiagnostic]) ->
/// Adds a left margin to every line but the first, given a padding length and the label being /// Adds a left margin to every line but the first, given a padding length and the label being
/// displayed, keeping the provided highlighting. /// displayed, keeping the provided highlighting.
fn msg_to_buffer( fn msgs_to_buffer(
&self, &self,
buffer: &mut StyledBuffer, buffer: &mut StyledBuffer,
msg: &[(DiagnosticMessage, Style)], msgs: &[(DiagnosticMessage, Style)],
args: &FluentArgs<'_>, args: &FluentArgs<'_>,
padding: usize, padding: usize,
label: &str, label: &str,
@ -1267,7 +1267,7 @@ fn style_or_override(style: Style, override_: Option<Style>) -> Style {
// Provided the following diagnostic message: // Provided the following diagnostic message:
// //
// let msg = vec![ // let msgs = vec![
// (" // ("
// ("highlighted multiline\nstring to\nsee how it ", Style::NoStyle), // ("highlighted multiline\nstring to\nsee how it ", Style::NoStyle),
// ("looks", Style::Highlight), // ("looks", Style::Highlight),
@ -1284,7 +1284,7 @@ fn style_or_override(style: Style, override_: Option<Style>) -> Style {
// see how it *looks* with // see how it *looks* with
// very *weird* formats // very *weird* formats
// see? // see?
for (text, style) in msg.iter() { for (text, style) in msgs.iter() {
let text = self.translate_message(text, args).map_err(Report::new).unwrap(); let text = self.translate_message(text, args).map_err(Report::new).unwrap();
let text = &normalize_whitespace(&text); let text = &normalize_whitespace(&text);
let lines = text.split('\n').collect::<Vec<_>>(); let lines = text.split('\n').collect::<Vec<_>>();
@ -1303,10 +1303,10 @@ fn style_or_override(style: Style, override_: Option<Style>) -> Style {
} }
#[instrument(level = "trace", skip(self, args), ret)] #[instrument(level = "trace", skip(self, args), ret)]
fn emit_message_default( fn emit_messages_default_inner(
&mut self, &mut self,
msp: &MultiSpan, msp: &MultiSpan,
msg: &[(DiagnosticMessage, Style)], msgs: &[(DiagnosticMessage, Style)],
args: &FluentArgs<'_>, args: &FluentArgs<'_>,
code: &Option<DiagnosticId>, code: &Option<DiagnosticId>,
level: &Level, level: &Level,
@ -1327,7 +1327,7 @@ fn emit_message_default(
buffer.append(0, level.to_str(), Style::MainHeaderMsg); buffer.append(0, level.to_str(), Style::MainHeaderMsg);
buffer.append(0, ": ", Style::NoStyle); buffer.append(0, ": ", Style::NoStyle);
} }
self.msg_to_buffer(&mut buffer, msg, args, max_line_num_len, "note", None); self.msgs_to_buffer(&mut buffer, msgs, args, max_line_num_len, "note", None);
} else { } else {
let mut label_width = 0; let mut label_width = 0;
// The failure note level itself does not provide any useful diagnostic information // The failure note level itself does not provide any useful diagnostic information
@ -1360,7 +1360,7 @@ fn emit_message_default(
buffer.append(0, ": ", header_style); buffer.append(0, ": ", header_style);
label_width += 2; label_width += 2;
} }
for (text, _) in msg.iter() { for (text, _) in msgs.iter() {
let text = self.translate_message(text, args).map_err(Report::new).unwrap(); let text = self.translate_message(text, args).map_err(Report::new).unwrap();
// Account for newlines to align output to its label. // Account for newlines to align output to its label.
for (line, text) in normalize_whitespace(&text).lines().enumerate() { for (line, text) in normalize_whitespace(&text).lines().enumerate() {
@ -1747,7 +1747,7 @@ fn emit_suggestion_default(
buffer.append(0, level.to_str(), Style::Level(*level)); buffer.append(0, level.to_str(), Style::Level(*level));
buffer.append(0, ": ", Style::HeaderMsg); buffer.append(0, ": ", Style::HeaderMsg);
self.msg_to_buffer( self.msgs_to_buffer(
&mut buffer, &mut buffer,
&[(suggestion.msg.to_owned(), Style::NoStyle)], &[(suggestion.msg.to_owned(), Style::NoStyle)],
args, args,
@ -2074,7 +2074,7 @@ fn emit_suggestion_default(
fn emit_messages_default( fn emit_messages_default(
&mut self, &mut self,
level: &Level, level: &Level,
message: &[(DiagnosticMessage, Style)], messages: &[(DiagnosticMessage, Style)],
args: &FluentArgs<'_>, args: &FluentArgs<'_>,
code: &Option<DiagnosticId>, code: &Option<DiagnosticId>,
span: &MultiSpan, span: &MultiSpan,
@ -2089,9 +2089,9 @@ fn emit_messages_default(
num_decimal_digits(n) num_decimal_digits(n)
}; };
match self.emit_message_default( match self.emit_messages_default_inner(
span, span,
message, messages,
args, args,
code, code,
level, level,
@ -2119,9 +2119,9 @@ fn emit_messages_default(
if !self.short_message { if !self.short_message {
for child in children { for child in children {
let span = child.render_span.as_ref().unwrap_or(&child.span); let span = child.render_span.as_ref().unwrap_or(&child.span);
if let Err(err) = self.emit_message_default( if let Err(err) = self.emit_messages_default_inner(
span, span,
&child.message, &child.messages,
args, args,
&None, &None,
&child.level, &child.level,
@ -2138,7 +2138,7 @@ fn emit_messages_default(
// do not display this suggestion, it is meant only for tools // do not display this suggestion, it is meant only for tools
} }
SuggestionStyle::HideCodeAlways => { SuggestionStyle::HideCodeAlways => {
if let Err(e) = self.emit_message_default( if let Err(e) = self.emit_messages_default_inner(
&MultiSpan::new(), &MultiSpan::new(),
&[(sugg.msg.to_owned(), Style::HeaderMsg)], &[(sugg.msg.to_owned(), Style::HeaderMsg)],
args, args,

View File

@ -398,7 +398,7 @@ fn reset(&mut self) -> io::Result<()> {
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap(); let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
let output = String::from_utf8(output).unwrap(); let output = String::from_utf8(output).unwrap();
let translated_message = je.translate_messages(&diag.message, &args); let translated_message = je.translate_messages(&diag.messages, &args);
Diagnostic { Diagnostic {
message: translated_message.to_string(), message: translated_message.to_string(),
code: DiagnosticCode::map_opt_string(diag.code.clone(), je), code: DiagnosticCode::map_opt_string(diag.code.clone(), je),
@ -419,7 +419,7 @@ fn from_sub_diagnostic(
args: &FluentArgs<'_>, args: &FluentArgs<'_>,
je: &JsonEmitter, je: &JsonEmitter,
) -> Diagnostic { ) -> Diagnostic {
let translated_message = je.translate_messages(&diag.message, args); let translated_message = je.translate_messages(&diag.messages, args);
Diagnostic { Diagnostic {
message: translated_message.to_string(), message: translated_message.to_string(),
code: None, code: None,

View File

@ -1551,7 +1551,7 @@ fn flush_delayed(
&mut out, &mut out,
"delayed span bug: {}\n{}\n", "delayed span bug: {}\n{}\n",
bug.inner bug.inner
.styled_message() .messages()
.iter() .iter()
.filter_map(|(msg, _)| msg.as_str()) .filter_map(|(msg, _)| msg.as_str())
.collect::<String>(), .collect::<String>(),

View File

@ -224,11 +224,11 @@ pub(super) fn emit_frag_parse_err(
) { ) {
// FIXME(davidtwco): avoid depending on the error message text // FIXME(davidtwco): avoid depending on the error message text
if parser.token == token::Eof if parser.token == token::Eof
&& let DiagnosticMessage::Str(message) = &e.message[0].0 && let DiagnosticMessage::Str(message) = &e.messages[0].0
&& message.ends_with(", found `<eof>`") && message.ends_with(", found `<eof>`")
{ {
let msg = &e.message[0]; let msg = &e.messages[0];
e.message[0] = ( e.messages[0] = (
DiagnosticMessage::from(format!( DiagnosticMessage::from(format!(
"macro expansion ends with an incomplete expression: {}", "macro expansion ends with an incomplete expression: {}",
message.replace(", found `<eof>`", ""), message.replace(", found `<eof>`", ""),

View File

@ -3693,7 +3693,7 @@ fn smart_resolve_path_fragment(
let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node); let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
// overwrite all properties with the parent's error message // overwrite all properties with the parent's error message
err.message = take(&mut parent_err.message); err.messages = take(&mut parent_err.messages);
err.code = take(&mut parent_err.code); err.code = take(&mut parent_err.code);
swap(&mut err.span, &mut parent_err.span); swap(&mut err.span, &mut parent_err.span);
err.children = take(&mut parent_err.children); err.children = take(&mut parent_err.children);

View File

@ -1384,7 +1384,7 @@ fn suggest_add_reference_to_arg(
if has_custom_message { if has_custom_message {
err.note(msg); err.note(msg);
} else { } else {
err.message = err.messages =
vec![(rustc_errors::DiagnosticMessage::from(msg), Style::NoStyle)]; vec![(rustc_errors::DiagnosticMessage::from(msg), Style::NoStyle)];
} }
let mut file = None; let mut file = None;

View File

@ -161,7 +161,7 @@ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
let fluent_args = to_fluent_args(diag.args()); let fluent_args = to_fluent_args(diag.args());
let translated_main_message = self let translated_main_message = self
.translate_message(&diag.message[0].0, &fluent_args) .translate_message(&diag.messages[0].0, &fluent_args)
.unwrap_or_else(|e| panic!("{e}")); .unwrap_or_else(|e| panic!("{e}"));
buffer.messages.push(format!("error from rustc: {translated_main_message}")); buffer.messages.push(format!("error from rustc: {translated_main_message}"));

View File

@ -370,7 +370,7 @@ fn emit_diagnostic(&mut self, _db: &Diagnostic) {
fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic { fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic {
let mut diag = Diagnostic::new(level, ""); let mut diag = Diagnostic::new(level, "");
diag.message.clear(); diag.messages.clear();
if let Some(span) = span { if let Some(span) = span {
diag.span = span; diag.span = span;
} }