Remove RunCompiler::emitter
.
It's no longer used.
This commit is contained in:
parent
bf286a82e2
commit
641f8249f9
@ -35,7 +35,7 @@
|
||||
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<Box<dyn FileLoader + Send + Sync>>,
|
||||
emitter: Option<Box<dyn Write + Send>>,
|
||||
make_codegen_backend:
|
||||
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + 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 @@ pub fn set_make_codegen_backend(
|
||||
self
|
||||
}
|
||||
|
||||
/// Emit diagnostics to the specified location.
|
||||
///
|
||||
/// Used by RLS.
|
||||
pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &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<Box<dyn FileLoader + Send + Sync>>,
|
||||
@ -191,27 +187,19 @@ pub fn set_file_loader(
|
||||
|
||||
/// 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<Box<dyn FileLoader + Send + Sync>>,
|
||||
emitter: Option<Box<dyn Write + Send>>,
|
||||
make_codegen_backend: Option<
|
||||
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + 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,
|
||||
|
@ -17,7 +17,7 @@
|
||||
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<PathBuf>,
|
||||
pub output_file: Option<PathBuf>,
|
||||
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
|
||||
pub diagnostic_output: DiagnosticOutput,
|
||||
|
||||
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||
|
||||
@ -284,7 +283,6 @@ pub fn create_compiler_and_run<R>(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,
|
||||
|
@ -17,7 +17,7 @@
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
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<String>)>,
|
||||
check_cfg: CheckCfg,
|
||||
diagnostic_output: DiagnosticOutput,
|
||||
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
||||
input_path: Option<PathBuf>,
|
||||
lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||
@ -104,7 +103,6 @@ pub fn create_session(
|
||||
input_path,
|
||||
bundle,
|
||||
descriptions,
|
||||
diagnostic_output,
|
||||
lint_caps,
|
||||
file_loader,
|
||||
target_override,
|
||||
|
@ -44,7 +44,6 @@
|
||||
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<SourceMap>,
|
||||
bundle: Option<Lrc<FluentBundle>>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
emitter_dest: Option<Box<dyn Write + Send>>,
|
||||
) -> Box<dyn Emitter + sync::Send> {
|
||||
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<dyn Write + Send>),
|
||||
}
|
||||
|
||||
// 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<PathBuf>,
|
||||
bundle: Option<Lrc<rustc_errors::FluentBundle>>,
|
||||
registry: rustc_errors::registry::Registry,
|
||||
diagnostics_output: DiagnosticOutput,
|
||||
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
||||
target_override: Option<Target>,
|
||||
@ -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,
|
||||
|
@ -14,7 +14,6 @@
|
||||
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)),
|
||||
|
@ -14,7 +14,7 @@
|
||||
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)),
|
||||
|
@ -5,7 +5,6 @@
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user