mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Adjust uses of format_diag_message to remove unwrap
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
//! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::error::Report;
|
||||
use std::fmt::Debug;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
@@ -361,10 +360,7 @@ fn emit_messages_default(
|
||||
if substitutions.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut msg = format_diag_message(&suggestion.msg, args)
|
||||
.map_err(Report::new)
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let mut msg = format_diag_message(&suggestion.msg, args).to_string();
|
||||
|
||||
let lo = substitutions
|
||||
.iter()
|
||||
@@ -547,7 +543,7 @@ fn pre_style_msgs(
|
||||
) -> String {
|
||||
msgs.iter()
|
||||
.filter_map(|(m, style)| {
|
||||
let text = format_diag_message(m, args).map_err(Report::new).unwrap();
|
||||
let text = format_diag_message(m, args);
|
||||
let style = style.anstyle(level);
|
||||
if text.is_empty() { None } else { Some(format!("{style}{text}{style:#}")) }
|
||||
})
|
||||
@@ -694,9 +690,7 @@ fn collect_annotations(
|
||||
|
||||
let kind = if is_primary { AnnotationKind::Primary } else { AnnotationKind::Context };
|
||||
|
||||
let label = label.as_ref().map(|m| {
|
||||
normalize_whitespace(&format_diag_message(m, args).map_err(Report::new).unwrap())
|
||||
});
|
||||
let label = label.as_ref().map(|m| normalize_whitespace(&format_diag_message(m, args)));
|
||||
|
||||
let ann = Annotation { kind, span, label };
|
||||
if sm.is_valid_span(ann.span).is_ok() {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
//! The output types are defined in `rustc_session::config::ErrorOutputType`.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::error::Report;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{self, IsTerminal};
|
||||
use std::iter;
|
||||
@@ -106,7 +105,7 @@ fn primary_span_formatted(
|
||||
fluent_args: &FluentArgs<'_>,
|
||||
) {
|
||||
if let Some((sugg, rest)) = suggestions.split_first() {
|
||||
let msg = format_diag_message(&sugg.msg, fluent_args).map_err(Report::new).unwrap();
|
||||
let msg = format_diag_message(&sugg.msg, fluent_args);
|
||||
if rest.is_empty()
|
||||
// ^ if there is only one suggestion
|
||||
// don't display multi-suggestions as labels
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
// FIXME: spec the JSON output properly.
|
||||
|
||||
use std::error::Report;
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -301,8 +300,7 @@ impl Diagnostic {
|
||||
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
|
||||
let args = to_fluent_args(diag.args.iter());
|
||||
let sugg_to_diag = |sugg: &CodeSuggestion| {
|
||||
let translated_message =
|
||||
format_diag_message(&sugg.msg, &args).map_err(Report::new).unwrap();
|
||||
let translated_message = format_diag_message(&sugg.msg, &args);
|
||||
Diagnostic {
|
||||
message: translated_message.to_string(),
|
||||
code: None,
|
||||
@@ -417,10 +415,7 @@ fn from_span_label(
|
||||
Self::from_span_etc(
|
||||
span.span,
|
||||
span.is_primary,
|
||||
span.label
|
||||
.as_ref()
|
||||
.map(|m| format_diag_message(m, args).unwrap())
|
||||
.map(|m| m.to_string()),
|
||||
span.label.as_ref().map(|m| format_diag_message(m, args)).map(|m| m.to_string()),
|
||||
suggestion,
|
||||
je,
|
||||
)
|
||||
|
||||
@@ -31,12 +31,7 @@ pub fn format_diag_messages(
|
||||
messages: &[(DiagMessage, Style)],
|
||||
args: &FluentArgs<'_>,
|
||||
) -> Cow<'static, str> {
|
||||
Cow::Owned(
|
||||
messages
|
||||
.iter()
|
||||
.map(|(m, _)| format_diag_message(m, args).map_err(Report::new).unwrap())
|
||||
.collect::<String>(),
|
||||
)
|
||||
Cow::Owned(messages.iter().map(|(m, _)| format_diag_message(m, args)).collect::<String>())
|
||||
}
|
||||
|
||||
/// Convert a `DiagMessage` to a string
|
||||
|
||||
@@ -151,8 +151,7 @@ fn emit_diagnostic(&mut self, diag: DiagInner) {
|
||||
let mut buffer = self.buffer.borrow_mut();
|
||||
|
||||
let fluent_args = to_fluent_args(diag.args.iter());
|
||||
let translated_main_message = format_diag_message(&diag.messages[0].0, &fluent_args)
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
let translated_main_message = format_diag_message(&diag.messages[0].0, &fluent_args);
|
||||
|
||||
buffer.messages.push(format!("error from rustc: {translated_main_message}"));
|
||||
if diag.is_error() {
|
||||
|
||||
Reference in New Issue
Block a user