1
Fork 0

Rollup merge of #106427 - mejrs:translation_errors, r=davidtwco

Improve fluent error messages

These have been really frustrating me while migrating diagnostics.
This commit is contained in:
nils 2023-01-11 17:30:54 +01:00 committed by GitHub
commit 73476554e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 407 additions and 82 deletions

View file

@ -11,6 +11,10 @@
#![feature(never_type)]
#![feature(result_option_inspect)]
#![feature(rustc_attrs)]
#![feature(yeet_expr)]
#![feature(try_blocks)]
#![feature(box_patterns)]
#![feature(error_reporter)]
#![allow(incomplete_features)]
#[macro_use]
@ -41,6 +45,7 @@ use rustc_span::HashStableContext;
use rustc_span::{Loc, Span};
use std::borrow::Cow;
use std::error::Report;
use std::fmt;
use std::hash::Hash;
use std::num::NonZeroUsize;
@ -54,11 +59,14 @@ mod diagnostic;
mod diagnostic_builder;
mod diagnostic_impls;
pub mod emitter;
pub mod error;
pub mod json;
mod lock;
pub mod registry;
mod snippet;
mod styled_buffer;
#[cfg(test)]
mod tests;
pub mod translation;
pub use diagnostic_builder::IntoDiagnostic;
@ -616,7 +624,14 @@ impl Handler {
) -> SubdiagnosticMessage {
let inner = self.inner.borrow();
let args = crate::translation::to_fluent_args(args);
SubdiagnosticMessage::Eager(inner.emitter.translate_message(&message, &args).to_string())
SubdiagnosticMessage::Eager(
inner
.emitter
.translate_message(&message, &args)
.map_err(Report::new)
.unwrap()
.to_string(),
)
}
// This is here to not allow mutation of flags;