errors: implement fallback diagnostic translation
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
This commit is contained in:
parent
c45f29595d
commit
7f91697b50
46 changed files with 919 additions and 293 deletions
|
@ -8,7 +8,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||
use rustc_data_structures::sync::{Lock, Lrc};
|
||||
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
||||
use rustc_errors::{
|
||||
error_code, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
|
||||
error_code, fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder,
|
||||
ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
||||
use rustc_span::edition::Edition;
|
||||
|
@ -173,8 +174,15 @@ pub struct ParseSess {
|
|||
impl ParseSess {
|
||||
/// Used for testing.
|
||||
pub fn new(file_path_mapping: FilePathMapping) -> Self {
|
||||
let fallback_bundle = fallback_fluent_bundle();
|
||||
let sm = Lrc::new(SourceMap::new(file_path_mapping));
|
||||
let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, None, Some(sm.clone()));
|
||||
let handler = Handler::with_tty_emitter(
|
||||
ColorConfig::Auto,
|
||||
true,
|
||||
None,
|
||||
Some(sm.clone()),
|
||||
fallback_bundle,
|
||||
);
|
||||
ParseSess::with_span_handler(handler, sm)
|
||||
}
|
||||
|
||||
|
@ -203,8 +211,10 @@ impl ParseSess {
|
|||
}
|
||||
|
||||
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
|
||||
let fallback_bundle = fallback_fluent_bundle();
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let fatal_handler = Handler::with_tty_emitter(ColorConfig::Auto, false, None, None);
|
||||
let fatal_handler =
|
||||
Handler::with_tty_emitter(ColorConfig::Auto, false, None, None, fallback_bundle);
|
||||
let handler = Handler::with_emitter(
|
||||
false,
|
||||
None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue