mirror of https://github.com/rust-lang/rust.git
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:
parent
d7a3b6291c
commit
824667f753
|
@ -102,7 +102,7 @@ pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
|
|||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
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 mut diag =
|
||||
|
|
|
@ -986,7 +986,7 @@ pub struct CguMessage;
|
|||
type DiagnosticArgName<'source> = Cow<'source, str>;
|
||||
|
||||
struct Diagnostic {
|
||||
msg: Vec<(DiagnosticMessage, Style)>,
|
||||
msgs: Vec<(DiagnosticMessage, Style)>,
|
||||
args: FxHashMap<DiagnosticArgName<'static>, rustc_errors::DiagnosticArgValue<'static>>,
|
||||
code: Option<DiagnosticId>,
|
||||
lvl: Level,
|
||||
|
@ -1799,14 +1799,14 @@ impl Emitter for SharedEmitter {
|
|||
let args: FxHashMap<Cow<'_, str>, rustc_errors::DiagnosticArgValue<'_>> =
|
||||
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
|
||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||
msg: diag.message.clone(),
|
||||
msgs: diag.messages.clone(),
|
||||
args: args.clone(),
|
||||
code: diag.code.clone(),
|
||||
lvl: diag.level(),
|
||||
})));
|
||||
for child in &diag.children {
|
||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||
msg: child.message.clone(),
|
||||
msgs: child.messages.clone(),
|
||||
args: args.clone(),
|
||||
code: None,
|
||||
lvl: child.level,
|
||||
|
@ -1838,7 +1838,7 @@ impl SharedEmitterMain {
|
|||
match message {
|
||||
Ok(SharedEmitterMessage::Diagnostic(diag)) => {
|
||||
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 {
|
||||
d.code(code);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ impl Emitter for AnnotateSnippetEmitterWriter {
|
|||
|
||||
self.emit_messages_default(
|
||||
&diag.level,
|
||||
&diag.message,
|
||||
&diag.messages,
|
||||
&fluent_args,
|
||||
&diag.code,
|
||||
&primary_span,
|
||||
|
|
|
@ -103,7 +103,7 @@ pub struct Diagnostic {
|
|||
// outside of what methods in this crate themselves allow.
|
||||
pub(crate) level: Level,
|
||||
|
||||
pub message: Vec<(DiagnosticMessage, Style)>,
|
||||
pub messages: Vec<(DiagnosticMessage, Style)>,
|
||||
pub code: Option<DiagnosticId>,
|
||||
pub span: MultiSpan,
|
||||
pub children: Vec<SubDiagnostic>,
|
||||
|
@ -161,7 +161,7 @@ pub enum DiagnosticId {
|
|||
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
|
||||
pub struct SubDiagnostic {
|
||||
pub level: Level,
|
||||
pub message: Vec<(DiagnosticMessage, Style)>,
|
||||
pub messages: Vec<(DiagnosticMessage, Style)>,
|
||||
pub span: MultiSpan,
|
||||
pub render_span: Option<MultiSpan>,
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ impl Diagnostic {
|
|||
pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self {
|
||||
Diagnostic {
|
||||
level,
|
||||
message: messages,
|
||||
messages,
|
||||
code: None,
|
||||
span: MultiSpan::new(),
|
||||
children: vec![],
|
||||
|
@ -905,7 +905,7 @@ impl Diagnostic {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -932,8 +932,8 @@ impl Diagnostic {
|
|||
self.args = args;
|
||||
}
|
||||
|
||||
pub fn styled_message(&self) -> &[(DiagnosticMessage, Style)] {
|
||||
&self.message
|
||||
pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
|
||||
&self.messages
|
||||
}
|
||||
|
||||
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
|
||||
|
@ -944,7 +944,7 @@ impl Diagnostic {
|
|||
attr: impl Into<SubdiagnosticMessage>,
|
||||
) -> DiagnosticMessage {
|
||||
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())
|
||||
}
|
||||
|
||||
|
@ -961,7 +961,7 @@ impl Diagnostic {
|
|||
) {
|
||||
let sub = SubDiagnostic {
|
||||
level,
|
||||
message: vec![(
|
||||
messages: vec![(
|
||||
self.subdiagnostic_message_to_diagnostic_message(message),
|
||||
Style::NoStyle,
|
||||
)],
|
||||
|
@ -976,15 +976,15 @@ impl Diagnostic {
|
|||
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
|
||||
&mut self,
|
||||
level: Level,
|
||||
message: Vec<(M, Style)>,
|
||||
messages: Vec<(M, Style)>,
|
||||
span: MultiSpan,
|
||||
render_span: Option<MultiSpan>,
|
||||
) {
|
||||
let message = message
|
||||
let messages = messages
|
||||
.into_iter()
|
||||
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
|
||||
.collect();
|
||||
let sub = SubDiagnostic { level, message, span, render_span };
|
||||
let sub = SubDiagnostic { level, messages, span, render_span };
|
||||
self.children.push(sub);
|
||||
}
|
||||
|
||||
|
@ -1002,7 +1002,7 @@ impl Diagnostic {
|
|||
) {
|
||||
(
|
||||
&self.level,
|
||||
&self.message,
|
||||
&self.messages,
|
||||
self.args().collect(),
|
||||
&self.code,
|
||||
&self.span,
|
||||
|
|
|
@ -350,7 +350,7 @@ pub trait Emitter: Translate {
|
|||
|
||||
children.push(SubDiagnostic {
|
||||
level: Level::Note,
|
||||
message: vec![(DiagnosticMessage::from(msg), Style::NoStyle)],
|
||||
messages: vec![(DiagnosticMessage::from(msg), Style::NoStyle)],
|
||||
span: MultiSpan::new(),
|
||||
render_span: None,
|
||||
});
|
||||
|
@ -533,7 +533,7 @@ impl Emitter for EmitterWriter {
|
|||
|
||||
self.emit_messages_default(
|
||||
&diag.level,
|
||||
&diag.message,
|
||||
&diag.messages,
|
||||
&fluent_args,
|
||||
&diag.code,
|
||||
&primary_span,
|
||||
|
@ -1228,10 +1228,10 @@ impl EmitterWriter {
|
|||
|
||||
/// Adds a left margin to every line but the first, given a padding length and the label being
|
||||
/// displayed, keeping the provided highlighting.
|
||||
fn msg_to_buffer(
|
||||
fn msgs_to_buffer(
|
||||
&self,
|
||||
buffer: &mut StyledBuffer,
|
||||
msg: &[(DiagnosticMessage, Style)],
|
||||
msgs: &[(DiagnosticMessage, Style)],
|
||||
args: &FluentArgs<'_>,
|
||||
padding: usize,
|
||||
label: &str,
|
||||
|
@ -1267,7 +1267,7 @@ impl EmitterWriter {
|
|||
|
||||
// Provided the following diagnostic message:
|
||||
//
|
||||
// let msg = vec![
|
||||
// let msgs = vec![
|
||||
// ("
|
||||
// ("highlighted multiline\nstring to\nsee how it ", Style::NoStyle),
|
||||
// ("looks", Style::Highlight),
|
||||
|
@ -1284,7 +1284,7 @@ impl EmitterWriter {
|
|||
// see how it *looks* with
|
||||
// very *weird* formats
|
||||
// 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 = &normalize_whitespace(&text);
|
||||
let lines = text.split('\n').collect::<Vec<_>>();
|
||||
|
@ -1303,10 +1303,10 @@ impl EmitterWriter {
|
|||
}
|
||||
|
||||
#[instrument(level = "trace", skip(self, args), ret)]
|
||||
fn emit_message_default(
|
||||
fn emit_messages_default_inner(
|
||||
&mut self,
|
||||
msp: &MultiSpan,
|
||||
msg: &[(DiagnosticMessage, Style)],
|
||||
msgs: &[(DiagnosticMessage, Style)],
|
||||
args: &FluentArgs<'_>,
|
||||
code: &Option<DiagnosticId>,
|
||||
level: &Level,
|
||||
|
@ -1327,7 +1327,7 @@ impl EmitterWriter {
|
|||
buffer.append(0, level.to_str(), Style::MainHeaderMsg);
|
||||
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 {
|
||||
let mut label_width = 0;
|
||||
// The failure note level itself does not provide any useful diagnostic information
|
||||
|
@ -1360,7 +1360,7 @@ impl EmitterWriter {
|
|||
buffer.append(0, ": ", header_style);
|
||||
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();
|
||||
// Account for newlines to align output to its label.
|
||||
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
|
||||
|
@ -1747,7 +1747,7 @@ impl EmitterWriter {
|
|||
buffer.append(0, level.to_str(), Style::Level(*level));
|
||||
buffer.append(0, ": ", Style::HeaderMsg);
|
||||
|
||||
self.msg_to_buffer(
|
||||
self.msgs_to_buffer(
|
||||
&mut buffer,
|
||||
&[(suggestion.msg.to_owned(), Style::NoStyle)],
|
||||
args,
|
||||
|
@ -2074,7 +2074,7 @@ impl EmitterWriter {
|
|||
fn emit_messages_default(
|
||||
&mut self,
|
||||
level: &Level,
|
||||
message: &[(DiagnosticMessage, Style)],
|
||||
messages: &[(DiagnosticMessage, Style)],
|
||||
args: &FluentArgs<'_>,
|
||||
code: &Option<DiagnosticId>,
|
||||
span: &MultiSpan,
|
||||
|
@ -2089,9 +2089,9 @@ impl EmitterWriter {
|
|||
num_decimal_digits(n)
|
||||
};
|
||||
|
||||
match self.emit_message_default(
|
||||
match self.emit_messages_default_inner(
|
||||
span,
|
||||
message,
|
||||
messages,
|
||||
args,
|
||||
code,
|
||||
level,
|
||||
|
@ -2119,9 +2119,9 @@ impl EmitterWriter {
|
|||
if !self.short_message {
|
||||
for child in children {
|
||||
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,
|
||||
&child.message,
|
||||
&child.messages,
|
||||
args,
|
||||
&None,
|
||||
&child.level,
|
||||
|
@ -2138,7 +2138,7 @@ impl EmitterWriter {
|
|||
// do not display this suggestion, it is meant only for tools
|
||||
}
|
||||
SuggestionStyle::HideCodeAlways => {
|
||||
if let Err(e) = self.emit_message_default(
|
||||
if let Err(e) = self.emit_messages_default_inner(
|
||||
&MultiSpan::new(),
|
||||
&[(sugg.msg.to_owned(), Style::HeaderMsg)],
|
||||
args,
|
||||
|
|
|
@ -398,7 +398,7 @@ impl Diagnostic {
|
|||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().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 {
|
||||
message: translated_message.to_string(),
|
||||
code: DiagnosticCode::map_opt_string(diag.code.clone(), je),
|
||||
|
@ -419,7 +419,7 @@ impl Diagnostic {
|
|||
args: &FluentArgs<'_>,
|
||||
je: &JsonEmitter,
|
||||
) -> Diagnostic {
|
||||
let translated_message = je.translate_messages(&diag.message, args);
|
||||
let translated_message = je.translate_messages(&diag.messages, args);
|
||||
Diagnostic {
|
||||
message: translated_message.to_string(),
|
||||
code: None,
|
||||
|
|
|
@ -1551,7 +1551,7 @@ impl DiagCtxtInner {
|
|||
&mut out,
|
||||
"delayed span bug: {}\n{}\n",
|
||||
bug.inner
|
||||
.styled_message()
|
||||
.messages()
|
||||
.iter()
|
||||
.filter_map(|(msg, _)| msg.as_str())
|
||||
.collect::<String>(),
|
||||
|
|
|
@ -224,11 +224,11 @@ pub(super) fn emit_frag_parse_err(
|
|||
) {
|
||||
// FIXME(davidtwco): avoid depending on the error message text
|
||||
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>`")
|
||||
{
|
||||
let msg = &e.message[0];
|
||||
e.message[0] = (
|
||||
let msg = &e.messages[0];
|
||||
e.messages[0] = (
|
||||
DiagnosticMessage::from(format!(
|
||||
"macro expansion ends with an incomplete expression: {}",
|
||||
message.replace(", found `<eof>`", ""),
|
||||
|
|
|
@ -3693,7 +3693,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
|
||||
|
||||
// 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);
|
||||
swap(&mut err.span, &mut parent_err.span);
|
||||
err.children = take(&mut parent_err.children);
|
||||
|
|
|
@ -1384,7 +1384,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if has_custom_message {
|
||||
err.note(msg);
|
||||
} else {
|
||||
err.message =
|
||||
err.messages =
|
||||
vec![(rustc_errors::DiagnosticMessage::from(msg), Style::NoStyle)];
|
||||
}
|
||||
let mut file = None;
|
||||
|
|
|
@ -161,7 +161,7 @@ impl Emitter for BufferEmitter {
|
|||
|
||||
let fluent_args = to_fluent_args(diag.args());
|
||||
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}"));
|
||||
|
||||
buffer.messages.push(format!("error from rustc: {translated_main_message}"));
|
||||
|
|
|
@ -370,7 +370,7 @@ mod tests {
|
|||
|
||||
fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic {
|
||||
let mut diag = Diagnostic::new(level, "");
|
||||
diag.message.clear();
|
||||
diag.messages.clear();
|
||||
if let Some(span) = span {
|
||||
diag.span = span;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue