From 641f8249f99b407af7e5376b098323926eab1696 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 13 Oct 2022 10:23:23 +1100 Subject: [PATCH] Remove `RunCompiler::emitter`. It's no longer used. --- compiler/rustc_driver/src/lib.rs | 33 +++------ compiler/rustc_interface/src/interface.rs | 4 +- compiler/rustc_interface/src/tests.rs | 13 +--- compiler/rustc_interface/src/util.rs | 4 +- compiler/rustc_session/src/session.rs | 69 ++++--------------- src/librustdoc/core.rs | 2 - src/librustdoc/doctest.rs | 3 +- src/test/run-make-fulldeps/issue-19371/foo.rs | 2 - 8 files changed, 29 insertions(+), 101 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 7d5604fcabc..f268d50e96e 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr use rustc_session::cstore::MetadataLoader; use rustc_session::getopts; use rustc_session::lint::{Lint, LintId}; -use rustc_session::{config, DiagnosticOutput, Session}; +use rustc_session::{config, Session}; use rustc_session::{early_error, early_error_no_abort, early_warn}; use rustc_span::source_map::{FileLoader, FileName}; use rustc_span::symbol::sym; @@ -147,19 +147,21 @@ pub struct RunCompiler<'a, 'b> { at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send), file_loader: Option>, - emitter: Option>, make_codegen_backend: Option Box + Send>>, } impl<'a, 'b> RunCompiler<'a, 'b> { pub fn new(at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send)) -> Self { - Self { at_args, callbacks, file_loader: None, emitter: None, make_codegen_backend: None } + Self { at_args, callbacks, file_loader: None, make_codegen_backend: None } } /// Set a custom codegen backend. /// - /// Used by cg_clif. + /// Has no uses within this repository, but is used by bjorn3 for "the + /// hotswapping branch of cg_clif" for "setting the codegen backend from a + /// custom driver where the custom codegen backend has arbitrary data." + /// (See #102759.) pub fn set_make_codegen_backend( &mut self, make_codegen_backend: Option< @@ -170,17 +172,11 @@ impl<'a, 'b> RunCompiler<'a, 'b> { self } - /// Emit diagnostics to the specified location. - /// - /// Used by RLS. - pub fn set_emitter(&mut self, emitter: Option>) -> &mut Self { - self.emitter = emitter; - self - } - /// Load files from sources other than the file system. /// - /// Used by RLS. + /// Has no uses within this repository, but may be used in the future by + /// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for + /// running rustc without having to save". (See #102759.) pub fn set_file_loader( &mut self, file_loader: Option>, @@ -191,27 +187,19 @@ impl<'a, 'b> RunCompiler<'a, 'b> { /// Parse args and run the compiler. pub fn run(self) -> interface::Result<()> { - run_compiler( - self.at_args, - self.callbacks, - self.file_loader, - self.emitter, - self.make_codegen_backend, - ) + run_compiler(self.at_args, self.callbacks, self.file_loader, self.make_codegen_backend) } } fn run_compiler( at_args: &[String], callbacks: &mut (dyn Callbacks + Send), file_loader: Option>, - emitter: Option>, make_codegen_backend: Option< Box Box + Send>, >, ) -> interface::Result<()> { let args = args::arg_expand_all(at_args); - let diagnostic_output = emitter.map_or(DiagnosticOutput::Default, DiagnosticOutput::Raw); let Some(matches) = handle_options(&args) else { return Ok(()) }; let sopts = config::build_session_options(&matches); @@ -233,7 +221,6 @@ fn run_compiler( output_file: ofile, output_dir: odir, file_loader, - diagnostic_output, lint_caps: Default::default(), parse_sess_created: None, register_lints: None, diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 949bd02ad68..134934c7ca6 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -17,7 +17,7 @@ use rustc_session::config::{self, CheckCfg, ErrorOutputType, Input, OutputFilena use rustc_session::early_error; use rustc_session::lint; use rustc_session::parse::{CrateConfig, ParseSess}; -use rustc_session::{DiagnosticOutput, Session}; +use rustc_session::Session; use rustc_span::source_map::{FileLoader, FileName}; use rustc_span::symbol::sym; use std::path::PathBuf; @@ -247,7 +247,6 @@ pub struct Config { pub output_dir: Option, pub output_file: Option, pub file_loader: Option>, - pub diagnostic_output: DiagnosticOutput, pub lint_caps: FxHashMap, @@ -284,7 +283,6 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R config.opts, config.crate_cfg, config.crate_check_cfg, - config.diagnostic_output, config.file_loader, config.input_path.clone(), config.lint_caps, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index d64cdcdbaa9..da3102ba7b0 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -17,7 +17,7 @@ use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, Switc use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; -use rustc_session::{build_session, getopts, DiagnosticOutput, Session}; +use rustc_session::{build_session, getopts, Session}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::symbol::sym; use rustc_span::SourceFileHashAlgorithm; @@ -40,16 +40,7 @@ fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) { let registry = registry::Registry::new(&[]); let (sessopts, cfg) = build_session_options_and_crate_config(matches); - let sess = build_session( - sessopts, - None, - None, - registry, - DiagnosticOutput::Default, - Default::default(), - None, - None, - ); + let sess = build_session(sessopts, None, None, registry, Default::default(), None, None); (sess, cfg) } diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index f7e70d355cf..3a9e491e289 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -18,7 +18,7 @@ use rustc_session::config::{self, CrateType}; use rustc_session::config::{ErrorOutputType, Input, OutputFilenames}; use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer}; use rustc_session::parse::CrateConfig; -use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session}; +use rustc_session::{early_error, filesearch, output, Session}; use rustc_span::edition::Edition; use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::source_map::FileLoader; @@ -65,7 +65,6 @@ pub fn create_session( sopts: config::Options, cfg: FxHashSet<(String, Option)>, check_cfg: CheckCfg, - diagnostic_output: DiagnosticOutput, file_loader: Option>, input_path: Option, lint_caps: FxHashMap, @@ -104,7 +103,6 @@ pub fn create_session( input_path, bundle, descriptions, - diagnostic_output, lint_caps, file_loader, target_override, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index beb22ab3eb9..b5e25f45fa7 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -44,7 +44,6 @@ use rustc_target::spec::{ use std::cell::{self, RefCell}; use std::env; use std::fmt; -use std::io::Write; use std::ops::{Div, Mul}; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -1213,11 +1212,10 @@ fn default_emitter( source_map: Lrc, bundle: Option>, fallback_bundle: LazyFallbackBundle, - emitter_dest: Option>, ) -> Box { let macro_backtrace = sopts.unstable_opts.macro_backtrace; - match (sopts.error_format, emitter_dest) { - (config::ErrorOutputType::HumanReadable(kind), dst) => { + match sopts.error_format { + config::ErrorOutputType::HumanReadable(kind) => { let (short, color_config) = kind.unzip(); if let HumanReadableErrorType::AnnotateSnippet(_) = kind { @@ -1230,33 +1228,20 @@ fn default_emitter( ); Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing)) } else { - let emitter = match dst { - None => EmitterWriter::stderr( - color_config, - Some(source_map), - bundle, - fallback_bundle, - short, - sopts.unstable_opts.teach, - sopts.diagnostic_width, - macro_backtrace, - ), - Some(dst) => EmitterWriter::new( - dst, - Some(source_map), - bundle, - fallback_bundle, - short, - false, // no teach messages when writing to a buffer - false, // no colors when writing to a buffer - None, // no diagnostic width - macro_backtrace, - ), - }; + let emitter = EmitterWriter::stderr( + color_config, + Some(source_map), + bundle, + fallback_bundle, + short, + sopts.unstable_opts.teach, + sopts.diagnostic_width, + macro_backtrace, + ); Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing)) } } - (config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new( + config::ErrorOutputType::Json { pretty, json_rendered } => Box::new( JsonEmitter::stderr( Some(registry), source_map, @@ -1269,28 +1254,9 @@ fn default_emitter( ) .ui_testing(sopts.unstable_opts.ui_testing), ), - (config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new( - JsonEmitter::new( - dst, - Some(registry), - source_map, - bundle, - fallback_bundle, - pretty, - json_rendered, - sopts.diagnostic_width, - macro_backtrace, - ) - .ui_testing(sopts.unstable_opts.ui_testing), - ), } } -pub enum DiagnosticOutput { - Default, - Raw(Box), -} - // JUSTIFICATION: literally session construction #[allow(rustc::bad_opt_access)] pub fn build_session( @@ -1298,7 +1264,6 @@ pub fn build_session( local_crate_source_file: Option, bundle: Option>, registry: rustc_errors::registry::Registry, - diagnostics_output: DiagnosticOutput, driver_lint_caps: FxHashMap, file_loader: Option>, target_override: Option, @@ -1314,11 +1279,6 @@ pub fn build_session( let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow); let can_emit_warnings = !(warnings_allow || cap_lints_allow); - let write_dest = match diagnostics_output { - DiagnosticOutput::Default => None, - DiagnosticOutput::Raw(write) => Some(write), - }; - let sysroot = match &sopts.maybe_sysroot { Some(sysroot) => sysroot.clone(), None => filesearch::get_or_default_sysroot(), @@ -1351,8 +1311,7 @@ pub fn build_session( rustc_errors::DEFAULT_LOCALE_RESOURCES, sopts.unstable_opts.translate_directionality_markers, ); - let emitter = - default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle, write_dest); + let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle); let span_diagnostic = rustc_errors::Handler::with_emitter_and_flags( emitter, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b463b934e29..858e939bd96 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -14,7 +14,6 @@ use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_resolve as resolve; use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::lint; -use rustc_session::DiagnosticOutput; use rustc_session::Session; use rustc_span::symbol::sym; use rustc_span::{source_map, Span, Symbol}; @@ -286,7 +285,6 @@ pub(crate) fn create_config( output_file: None, output_dir: None, file_loader: None, - diagnostic_output: DiagnosticOutput::Default, lint_caps, parse_sess_created: None, register_lints: Some(Box::new(crate::lint::register_lints)), diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index f4ec60735a8..ac8b5211878 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -14,7 +14,7 @@ use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::attr::InnerAttrPolicy; use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::parse::ParseSess; -use rustc_session::{lint, DiagnosticOutput, Session}; +use rustc_session::{lint, Session}; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMap; use rustc_span::symbol::sym; @@ -100,7 +100,6 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { output_file: None, output_dir: None, file_loader: None, - diagnostic_output: DiagnosticOutput::Default, lint_caps, parse_sess_created: None, register_lints: Some(Box::new(crate::lint::register_lints)), diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs index fd294b018af..7e1b6aeb315 100644 --- a/src/test/run-make-fulldeps/issue-19371/foo.rs +++ b/src/test/run-make-fulldeps/issue-19371/foo.rs @@ -5,7 +5,6 @@ extern crate rustc_driver; extern crate rustc_session; extern crate rustc_span; -use rustc_session::DiagnosticOutput; use rustc_session::config::{Input, Options, OutputType, OutputTypes}; use rustc_interface::interface; use rustc_span::source_map::FileName; @@ -55,7 +54,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { output_file: Some(output), output_dir: None, file_loader: None, - diagnostic_output: DiagnosticOutput::Default, lint_caps: Default::default(), parse_sess_created: None, register_lints: None,