Start moving rustc_driver to SessionDiagnostic
This commit is contained in:
parent
4d45b0745a
commit
dbe39d835e
6 changed files with 57 additions and 5 deletions
|
@ -3820,6 +3820,7 @@ dependencies = [
|
||||||
"rustc_interface",
|
"rustc_interface",
|
||||||
"rustc_lint",
|
"rustc_lint",
|
||||||
"rustc_log",
|
"rustc_log",
|
||||||
|
"rustc_macros",
|
||||||
"rustc_metadata",
|
"rustc_metadata",
|
||||||
"rustc_middle",
|
"rustc_middle",
|
||||||
"rustc_parse",
|
"rustc_parse",
|
||||||
|
|
|
@ -19,6 +19,7 @@ rustc_errors = { path = "../rustc_errors" }
|
||||||
rustc_feature = { path = "../rustc_feature" }
|
rustc_feature = { path = "../rustc_feature" }
|
||||||
rustc_hir = { path = "../rustc_hir" }
|
rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
|
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
|
||||||
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_metadata = { path = "../rustc_metadata" }
|
rustc_metadata = { path = "../rustc_metadata" }
|
||||||
rustc_parse = { path = "../rustc_parse" }
|
rustc_parse = { path = "../rustc_parse" }
|
||||||
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
|
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#![feature(once_cell)]
|
#![feature(once_cell)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
@ -56,6 +58,9 @@ use std::time::Instant;
|
||||||
|
|
||||||
pub mod args;
|
pub mod args;
|
||||||
pub mod pretty;
|
pub mod pretty;
|
||||||
|
mod session_diagnostics;
|
||||||
|
|
||||||
|
use crate::session_diagnostics::{RlinkNotAFile, RlinkUnableToDeserialize, RlinkUnableToRead};
|
||||||
|
|
||||||
/// Exit status code used for successful compilation and help output.
|
/// Exit status code used for successful compilation and help output.
|
||||||
pub const EXIT_SUCCESS: i32 = 0;
|
pub const EXIT_SUCCESS: i32 = 0;
|
||||||
|
@ -545,7 +550,11 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
|
||||||
|
|
||||||
fn show_content_with_pager(content: &str) {
|
fn show_content_with_pager(content: &str) {
|
||||||
let pager_name = env::var_os("PAGER").unwrap_or_else(|| {
|
let pager_name = env::var_os("PAGER").unwrap_or_else(|| {
|
||||||
if cfg!(windows) { OsString::from("more.com") } else { OsString::from("less") }
|
if cfg!(windows) {
|
||||||
|
OsString::from("more.com")
|
||||||
|
} else {
|
||||||
|
OsString::from("less")
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut fallback_to_println = false;
|
let mut fallback_to_println = false;
|
||||||
|
@ -581,18 +590,24 @@ pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Comp
|
||||||
sess.init_crate_types(collect_crate_types(sess, &[]));
|
sess.init_crate_types(collect_crate_types(sess, &[]));
|
||||||
let outputs = compiler.build_output_filenames(sess, &[]);
|
let outputs = compiler.build_output_filenames(sess, &[]);
|
||||||
let rlink_data = fs::read(file).unwrap_or_else(|err| {
|
let rlink_data = fs::read(file).unwrap_or_else(|err| {
|
||||||
sess.fatal(&format!("failed to read rlink file: {}", err));
|
sess.fatal(RlinkUnableToRead {
|
||||||
|
span: Default::default(),
|
||||||
|
error_message: err.to_string(),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
let codegen_results = match CodegenResults::deserialize_rlink(rlink_data) {
|
let codegen_results = match CodegenResults::deserialize_rlink(rlink_data) {
|
||||||
Ok(codegen) => codegen,
|
Ok(codegen) => codegen,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
sess.fatal(&format!("Could not deserialize .rlink file: {error}"));
|
sess.fatal(RlinkUnableToDeserialize {
|
||||||
|
span: Default::default(),
|
||||||
|
error_message: error.to_string(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let result = compiler.codegen_backend().link(sess, codegen_results, &outputs);
|
let result = compiler.codegen_backend().link(sess, codegen_results, &outputs);
|
||||||
abort_on_err(result, sess);
|
abort_on_err(result, sess);
|
||||||
} else {
|
} else {
|
||||||
sess.fatal("rlink must be a file")
|
sess.fatal(RlinkNotAFile { span: Default::default() })
|
||||||
}
|
}
|
||||||
Compilation::Stop
|
Compilation::Stop
|
||||||
} else {
|
} else {
|
||||||
|
@ -1116,7 +1131,11 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !result.is_empty() { Some((result, excluded_cargo_defaults)) } else { None }
|
if !result.is_empty() {
|
||||||
|
Some((result, excluded_cargo_defaults))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs a closure and catches unwinds triggered by fatal errors.
|
/// Runs a closure and catches unwinds triggered by fatal errors.
|
||||||
|
|
25
compiler/rustc_driver/src/session_diagnostics.rs
Normal file
25
compiler/rustc_driver/src/session_diagnostics.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use rustc_macros::SessionDiagnostic;
|
||||||
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(driver::rlink_unable_to_read)]
|
||||||
|
pub(crate) struct RlinkUnableToRead {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub error_message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(driver::rlink_unable_to_deserialize)]
|
||||||
|
pub(crate) struct RlinkUnableToDeserialize {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub error_message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(driver::rlink_no_a_file)]
|
||||||
|
pub(crate) struct RlinkNotAFile {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
5
compiler/rustc_error_messages/locales/en-US/driver.ftl
Normal file
5
compiler/rustc_error_messages/locales/en-US/driver.ftl
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
driver_rlink_unable_to_read = failed to read rlink file: `{$error_message}`
|
||||||
|
|
||||||
|
driver_rlink_unable_to_deserialize = could not deserialize .rlink file: `{$error_message}`
|
||||||
|
|
||||||
|
driver_rlink_no_a_file = rlink must be a file
|
|
@ -36,6 +36,7 @@ fluent_messages! {
|
||||||
borrowck => "../locales/en-US/borrowck.ftl",
|
borrowck => "../locales/en-US/borrowck.ftl",
|
||||||
builtin_macros => "../locales/en-US/builtin_macros.ftl",
|
builtin_macros => "../locales/en-US/builtin_macros.ftl",
|
||||||
const_eval => "../locales/en-US/const_eval.ftl",
|
const_eval => "../locales/en-US/const_eval.ftl",
|
||||||
|
driver => "../locales/en-US/driver.ftl",
|
||||||
expand => "../locales/en-US/expand.ftl",
|
expand => "../locales/en-US/expand.ftl",
|
||||||
interface => "../locales/en-US/interface.ftl",
|
interface => "../locales/en-US/interface.ftl",
|
||||||
lint => "../locales/en-US/lint.ftl",
|
lint => "../locales/en-US/lint.ftl",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue