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 DlltoolFailImportLibrary<'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(crate) enum Message<B: WriteBackendMethods> {
|
||||
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 @@ fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
|
||||
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 @@ pub fn check(&self, sess: &Session, blocking: bool) {
|
||||
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 @@ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||
|
||||
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 @@ pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
|
||||
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 @@ pub fn get_code(&self) -> Option<DiagnosticId> {
|
||||
}
|
||||
|
||||
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 @@ pub fn replace_args(
|
||||
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 @@ fn subdiagnostic_message_to_diagnostic_message(
|
||||
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 @@ pub fn sub(
|
||||
) {
|
||||
let sub = SubDiagnostic {
|
||||
level,
|
||||
message: vec![(
|
||||
messages: vec![(
|
||||
self.subdiagnostic_message_to_diagnostic_message(message),
|
||||
Style::NoStyle,
|
||||
)],
|
||||
@ -976,15 +976,15 @@ pub fn sub(
|
||||
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 @@ fn keys(
|
||||
) {
|
||||
(
|
||||
&self.level,
|
||||
&self.message,
|
||||
&self.messages,
|
||||
self.args().collect(),
|
||||
&self.code,
|
||||
&self.span,
|
||||
|
@ -350,7 +350,7 @@ fn fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||
|
||||
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 @@ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||
|
||||
self.emit_messages_default(
|
||||
&diag.level,
|
||||
&diag.message,
|
||||
&diag.messages,
|
||||
&fluent_args,
|
||||
&diag.code,
|
||||
&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
|
||||
/// 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 @@ fn style_or_override(style: Style, override_: Option<Style>) -> Style {
|
||||
|
||||
// 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 @@ fn style_or_override(style: Style, override_: Option<Style>) -> Style {
|
||||
// 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 @@ fn style_or_override(style: Style, override_: Option<Style>) -> Style {
|
||||
}
|
||||
|
||||
#[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 @@ fn emit_message_default(
|
||||
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 @@ fn emit_message_default(
|
||||
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 @@ fn emit_suggestion_default(
|
||||
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 @@ fn emit_suggestion_default(
|
||||
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 @@ fn emit_messages_default(
|
||||
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 @@ fn emit_messages_default(
|
||||
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 @@ fn emit_messages_default(
|
||||
// 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 @@ fn reset(&mut self) -> io::Result<()> {
|
||||
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 @@ fn from_sub_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 @@ fn flush_delayed(
|
||||
&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 @@ fn smart_resolve_path_fragment(
|
||||
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 @@ fn suggest_add_reference_to_arg(
|
||||
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 @@ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||
|
||||
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 @@ fn emit_diagnostic(&mut self, _db: &Diagnostic) {
|
||||
|
||||
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
Block a user