errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
f9216b7564
commit
d1fcf61117
151 changed files with 1721 additions and 1440 deletions
|
@ -18,6 +18,9 @@ pub mod errors;
|
|||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
|
||||
use rustc_macros::fluent_messages;
|
||||
|
||||
pub mod cgu_reuse_tracker;
|
||||
pub mod utils;
|
||||
pub use lint::{declare_lint, declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
|
@ -39,6 +42,8 @@ pub mod output;
|
|||
|
||||
pub use getopts;
|
||||
|
||||
fluent_messages! { "../locales/en-US.ftl" }
|
||||
|
||||
/// Requirements for a `StableHashingContext` to be used in this crate.
|
||||
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
||||
/// instead of implementing everything in `rustc_middle`.
|
||||
|
|
|
@ -226,8 +226,11 @@ pub struct ParseSess {
|
|||
|
||||
impl ParseSess {
|
||||
/// Used for testing.
|
||||
pub fn new(file_path_mapping: FilePathMapping) -> Self {
|
||||
let fallback_bundle = fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);
|
||||
pub fn new(
|
||||
locale_resources: &'static [&'static str],
|
||||
file_path_mapping: FilePathMapping,
|
||||
) -> Self {
|
||||
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
|
||||
let sm = Lrc::new(SourceMap::new(file_path_mapping));
|
||||
let handler = Handler::with_tty_emitter(
|
||||
ColorConfig::Auto,
|
||||
|
@ -265,7 +268,7 @@ impl ParseSess {
|
|||
}
|
||||
|
||||
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
|
||||
let fallback_bundle = fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);
|
||||
let fallback_bundle = fallback_fluent_bundle(&[], false);
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let fatal_handler =
|
||||
Handler::with_tty_emitter(ColorConfig::Auto, false, None, None, None, fallback_bundle);
|
||||
|
|
|
@ -1341,6 +1341,7 @@ pub fn build_session(
|
|||
io: CompilerIO,
|
||||
bundle: Option<Lrc<rustc_errors::FluentBundle>>,
|
||||
registry: rustc_errors::registry::Registry,
|
||||
fluent_resources: &'static [&'static str],
|
||||
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
||||
target_override: Option<Target>,
|
||||
|
@ -1385,7 +1386,7 @@ pub fn build_session(
|
|||
));
|
||||
|
||||
let fallback_bundle = fallback_fluent_bundle(
|
||||
rustc_errors::DEFAULT_LOCALE_RESOURCES,
|
||||
fluent_resources,
|
||||
sopts.unstable_opts.translate_directionality_markers,
|
||||
);
|
||||
let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle);
|
||||
|
@ -1629,8 +1630,13 @@ pub enum IncrCompSession {
|
|||
InvalidBecauseOfErrors { session_directory: PathBuf },
|
||||
}
|
||||
|
||||
// FIXME(#100717): early errors aren't translated at the moment, so this is fine, but it will need
|
||||
// to reference every crate that might emit an early error for translation to work.
|
||||
static EARLY_ERROR_LOCALE_RESOURCE: &'static [&'static str] =
|
||||
&[rustc_errors::DEFAULT_LOCALE_RESOURCE];
|
||||
|
||||
fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler {
|
||||
let fallback_bundle = fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);
|
||||
let fallback_bundle = fallback_fluent_bundle(EARLY_ERROR_LOCALE_RESOURCE, false);
|
||||
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
||||
config::ErrorOutputType::HumanReadable(kind) => {
|
||||
let (short, color_config) = kind.unzip();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue