diff options
Diffstat (limited to 'compiler/rustc_interface/src/interface.rs')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 6527e87d396..d58d60fc8be 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::Lrc; use rustc_errors::registry::Registry; -use rustc_errors::{ErrorGuaranteed, Handler}; +use rustc_errors::{DiagCtxt, ErrorGuaranteed}; use rustc_lint::LintStore; use rustc_middle::ty; use rustc_middle::util::Providers; @@ -18,7 +18,7 @@ use rustc_query_system::query::print_query_stack; use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileName}; use rustc_session::filesearch::sysroot_candidates; use rustc_session::parse::ParseSess; -use rustc_session::{lint, CompilerIO, EarlyErrorHandler, Session}; +use rustc_session::{lint, CompilerIO, EarlyDiagCtxt, Session}; use rustc_span::source_map::FileLoader; use rustc_span::symbol::sym; use rustc_span::FileName; @@ -42,7 +42,7 @@ pub struct Compiler { } /// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`. -pub(crate) fn parse_cfg(handler: &Handler, cfgs: Vec<String>) -> Cfg { +pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec<String>) -> Cfg { cfgs.into_iter() .map(|s| { let sess = ParseSess::with_silent_emitter(Some(format!( @@ -54,12 +54,11 @@ pub(crate) fn parse_cfg(handler: &Handler, cfgs: Vec<String>) -> Cfg { ($reason: expr) => { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - handler - .struct_fatal(format!( - concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), - s - )) - .emit(); + dcx.struct_fatal(format!( + concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), + s + )) + .emit(); }; } @@ -101,7 +100,7 @@ pub(crate) fn parse_cfg(handler: &Handler, cfgs: Vec<String>) -> Cfg { } /// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`. -pub(crate) fn parse_check_cfg(handler: &Handler, specs: Vec<String>) -> CheckCfg { +pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg { // If any --check-cfg is passed then exhaustive_values and exhaustive_names // are enabled by default. let exhaustive_names = !specs.is_empty(); @@ -118,12 +117,11 @@ pub(crate) fn parse_check_cfg(handler: &Handler, specs: Vec<String>) -> CheckCfg ($reason:expr) => { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - handler - .struct_fatal(format!( - concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"), - s - )) - .emit() + dcx.struct_fatal(format!( + concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"), + s + )) + .emit() }; } @@ -317,8 +315,8 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1); // Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread - let early_handler = EarlyErrorHandler::new(config.opts.error_format); - early_handler.initialize_checked_jobserver(); + let early_dcx = EarlyDiagCtxt::new(config.opts.error_format); + early_dcx.initialize_checked_jobserver(); util::run_in_thread_pool_with_globals( config.opts.edition, @@ -326,13 +324,13 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se || { crate::callbacks::setup_callbacks(); - let early_handler = EarlyErrorHandler::new(config.opts.error_format); + let early_dcx = EarlyDiagCtxt::new(config.opts.error_format); let codegen_backend = if let Some(make_codegen_backend) = config.make_codegen_backend { make_codegen_backend(&config.opts) } else { util::get_codegen_backend( - &early_handler, + &early_dcx, &config.opts.maybe_sysroot, config.opts.unstable_opts.codegen_backend.as_deref(), ) @@ -349,7 +347,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se ) { Ok(bundle) => bundle, Err(e) => { - early_handler.early_error(format!("failed to load fluent bundle: {e}")); + early_dcx.early_error(format!("failed to load fluent bundle: {e}")); } }; @@ -360,7 +358,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se let target_override = codegen_backend.target_override(&config.opts); let mut sess = rustc_session::build_session( - early_handler, + early_dcx, config.opts, CompilerIO { input: config.input, @@ -382,12 +380,12 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se codegen_backend.init(&sess); - let cfg = parse_cfg(&sess.diagnostic(), config.crate_cfg); + let cfg = parse_cfg(&sess.dcx(), config.crate_cfg); let mut cfg = config::build_configuration(&sess, cfg); util::add_configuration(&mut cfg, &mut sess, &*codegen_backend); sess.parse_sess.config = cfg; - let mut check_cfg = parse_check_cfg(&sess.diagnostic(), config.crate_check_cfg); + let mut check_cfg = parse_check_cfg(&sess.dcx(), config.crate_check_cfg); check_cfg.fill_well_known(&sess.target); sess.parse_sess.check_config = check_cfg; @@ -433,21 +431,21 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se } pub fn try_print_query_stack( - handler: &Handler, + dcx: &DiagCtxt, num_frames: Option<usize>, file: Option<std::fs::File>, ) { eprintln!("query stack during panic:"); // Be careful relying on global state here: this code is called from - // a panic hook, which means that the global `Handler` may be in a weird + // a panic hook, which means that the global `DiagCtxt` may be in a weird // state if it was responsible for triggering the panic. let i = ty::tls::with_context_opt(|icx| { if let Some(icx) = icx { ty::print::with_no_queries!(print_query_stack( QueryCtxt::new(icx.tcx), icx.query, - handler, + dcx, num_frames, file, )) |
