Skip to content

Commit 641f824

Browse files
committed
Remove RunCompiler::emitter.
It's no longer used.
1 parent bf286a8 commit 641f824

File tree

8 files changed

+29
-101
lines changed

8 files changed

+29
-101
lines changed

Diff for: compiler/rustc_driver/src/lib.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr
3535
use rustc_session::cstore::MetadataLoader;
3636
use rustc_session::getopts;
3737
use rustc_session::lint::{Lint, LintId};
38-
use rustc_session::{config, DiagnosticOutput, Session};
38+
use rustc_session::{config, Session};
3939
use rustc_session::{early_error, early_error_no_abort, early_warn};
4040
use rustc_span::source_map::{FileLoader, FileName};
4141
use rustc_span::symbol::sym;
@@ -147,19 +147,21 @@ pub struct RunCompiler<'a, 'b> {
147147
at_args: &'a [String],
148148
callbacks: &'b mut (dyn Callbacks + Send),
149149
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
150-
emitter: Option<Box<dyn Write + Send>>,
151150
make_codegen_backend:
152151
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
153152
}
154153

155154
impl<'a, 'b> RunCompiler<'a, 'b> {
156155
pub fn new(at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send)) -> Self {
157-
Self { at_args, callbacks, file_loader: None, emitter: None, make_codegen_backend: None }
156+
Self { at_args, callbacks, file_loader: None, make_codegen_backend: None }
158157
}
159158

160159
/// Set a custom codegen backend.
161160
///
162-
/// Used by cg_clif.
161+
/// Has no uses within this repository, but is used by bjorn3 for "the
162+
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
163+
/// custom driver where the custom codegen backend has arbitrary data."
164+
/// (See #102759.)
163165
pub fn set_make_codegen_backend(
164166
&mut self,
165167
make_codegen_backend: Option<
@@ -170,17 +172,11 @@ impl<'a, 'b> RunCompiler<'a, 'b> {
170172
self
171173
}
172174

173-
/// Emit diagnostics to the specified location.
174-
///
175-
/// Used by RLS.
176-
pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &mut Self {
177-
self.emitter = emitter;
178-
self
179-
}
180-
181175
/// Load files from sources other than the file system.
182176
///
183-
/// Used by RLS.
177+
/// Has no uses within this repository, but may be used in the future by
178+
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
179+
/// running rustc without having to save". (See #102759.)
184180
pub fn set_file_loader(
185181
&mut self,
186182
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
@@ -191,27 +187,19 @@ impl<'a, 'b> RunCompiler<'a, 'b> {
191187

192188
/// Parse args and run the compiler.
193189
pub fn run(self) -> interface::Result<()> {
194-
run_compiler(
195-
self.at_args,
196-
self.callbacks,
197-
self.file_loader,
198-
self.emitter,
199-
self.make_codegen_backend,
200-
)
190+
run_compiler(self.at_args, self.callbacks, self.file_loader, self.make_codegen_backend)
201191
}
202192
}
203193
fn run_compiler(
204194
at_args: &[String],
205195
callbacks: &mut (dyn Callbacks + Send),
206196
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
207-
emitter: Option<Box<dyn Write + Send>>,
208197
make_codegen_backend: Option<
209198
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
210199
>,
211200
) -> interface::Result<()> {
212201
let args = args::arg_expand_all(at_args);
213202

214-
let diagnostic_output = emitter.map_or(DiagnosticOutput::Default, DiagnosticOutput::Raw);
215203
let Some(matches) = handle_options(&args) else { return Ok(()) };
216204

217205
let sopts = config::build_session_options(&matches);
@@ -233,7 +221,6 @@ fn run_compiler(
233221
output_file: ofile,
234222
output_dir: odir,
235223
file_loader,
236-
diagnostic_output,
237224
lint_caps: Default::default(),
238225
parse_sess_created: None,
239226
register_lints: None,

Diff for: compiler/rustc_interface/src/interface.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_session::config::{self, CheckCfg, ErrorOutputType, Input, OutputFilena
1717
use rustc_session::early_error;
1818
use rustc_session::lint;
1919
use rustc_session::parse::{CrateConfig, ParseSess};
20-
use rustc_session::{DiagnosticOutput, Session};
20+
use rustc_session::Session;
2121
use rustc_span::source_map::{FileLoader, FileName};
2222
use rustc_span::symbol::sym;
2323
use std::path::PathBuf;
@@ -247,7 +247,6 @@ pub struct Config {
247247
pub output_dir: Option<PathBuf>,
248248
pub output_file: Option<PathBuf>,
249249
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
250-
pub diagnostic_output: DiagnosticOutput,
251250

252251
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
253252

@@ -284,7 +283,6 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
284283
config.opts,
285284
config.crate_cfg,
286285
config.crate_check_cfg,
287-
config.diagnostic_output,
288286
config.file_loader,
289287
config.input_path.clone(),
290288
config.lint_caps,

Diff for: compiler/rustc_interface/src/tests.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, Switc
1717
use rustc_session::lint::Level;
1818
use rustc_session::search_paths::SearchPath;
1919
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
20-
use rustc_session::{build_session, getopts, DiagnosticOutput, Session};
20+
use rustc_session::{build_session, getopts, Session};
2121
use rustc_span::edition::{Edition, DEFAULT_EDITION};
2222
use rustc_span::symbol::sym;
2323
use rustc_span::SourceFileHashAlgorithm;
@@ -40,16 +40,7 @@ fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options
4040
fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
4141
let registry = registry::Registry::new(&[]);
4242
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
43-
let sess = build_session(
44-
sessopts,
45-
None,
46-
None,
47-
registry,
48-
DiagnosticOutput::Default,
49-
Default::default(),
50-
None,
51-
None,
52-
);
43+
let sess = build_session(sessopts, None, None, registry, Default::default(), None, None);
5344
(sess, cfg)
5445
}
5546

Diff for: compiler/rustc_interface/src/util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_session::config::{self, CrateType};
1818
use rustc_session::config::{ErrorOutputType, Input, OutputFilenames};
1919
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
2020
use rustc_session::parse::CrateConfig;
21-
use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session};
21+
use rustc_session::{early_error, filesearch, output, Session};
2222
use rustc_span::edition::Edition;
2323
use rustc_span::lev_distance::find_best_match_for_name;
2424
use rustc_span::source_map::FileLoader;
@@ -65,7 +65,6 @@ pub fn create_session(
6565
sopts: config::Options,
6666
cfg: FxHashSet<(String, Option<String>)>,
6767
check_cfg: CheckCfg,
68-
diagnostic_output: DiagnosticOutput,
6968
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
7069
input_path: Option<PathBuf>,
7170
lint_caps: FxHashMap<lint::LintId, lint::Level>,
@@ -104,7 +103,6 @@ pub fn create_session(
104103
input_path,
105104
bundle,
106105
descriptions,
107-
diagnostic_output,
108106
lint_caps,
109107
file_loader,
110108
target_override,

Diff for: compiler/rustc_session/src/session.rs

+14-55
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use rustc_target::spec::{
4444
use std::cell::{self, RefCell};
4545
use std::env;
4646
use std::fmt;
47-
use std::io::Write;
4847
use std::ops::{Div, Mul};
4948
use std::path::{Path, PathBuf};
5049
use std::str::FromStr;
@@ -1213,11 +1212,10 @@ fn default_emitter(
12131212
source_map: Lrc<SourceMap>,
12141213
bundle: Option<Lrc<FluentBundle>>,
12151214
fallback_bundle: LazyFallbackBundle,
1216-
emitter_dest: Option<Box<dyn Write + Send>>,
12171215
) -> Box<dyn Emitter + sync::Send> {
12181216
let macro_backtrace = sopts.unstable_opts.macro_backtrace;
1219-
match (sopts.error_format, emitter_dest) {
1220-
(config::ErrorOutputType::HumanReadable(kind), dst) => {
1217+
match sopts.error_format {
1218+
config::ErrorOutputType::HumanReadable(kind) => {
12211219
let (short, color_config) = kind.unzip();
12221220

12231221
if let HumanReadableErrorType::AnnotateSnippet(_) = kind {
@@ -1230,33 +1228,20 @@ fn default_emitter(
12301228
);
12311229
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
12321230
} else {
1233-
let emitter = match dst {
1234-
None => EmitterWriter::stderr(
1235-
color_config,
1236-
Some(source_map),
1237-
bundle,
1238-
fallback_bundle,
1239-
short,
1240-
sopts.unstable_opts.teach,
1241-
sopts.diagnostic_width,
1242-
macro_backtrace,
1243-
),
1244-
Some(dst) => EmitterWriter::new(
1245-
dst,
1246-
Some(source_map),
1247-
bundle,
1248-
fallback_bundle,
1249-
short,
1250-
false, // no teach messages when writing to a buffer
1251-
false, // no colors when writing to a buffer
1252-
None, // no diagnostic width
1253-
macro_backtrace,
1254-
),
1255-
};
1231+
let emitter = EmitterWriter::stderr(
1232+
color_config,
1233+
Some(source_map),
1234+
bundle,
1235+
fallback_bundle,
1236+
short,
1237+
sopts.unstable_opts.teach,
1238+
sopts.diagnostic_width,
1239+
macro_backtrace,
1240+
);
12561241
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
12571242
}
12581243
}
1259-
(config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
1244+
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(
12601245
JsonEmitter::stderr(
12611246
Some(registry),
12621247
source_map,
@@ -1269,36 +1254,16 @@ fn default_emitter(
12691254
)
12701255
.ui_testing(sopts.unstable_opts.ui_testing),
12711256
),
1272-
(config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new(
1273-
JsonEmitter::new(
1274-
dst,
1275-
Some(registry),
1276-
source_map,
1277-
bundle,
1278-
fallback_bundle,
1279-
pretty,
1280-
json_rendered,
1281-
sopts.diagnostic_width,
1282-
macro_backtrace,
1283-
)
1284-
.ui_testing(sopts.unstable_opts.ui_testing),
1285-
),
12861257
}
12871258
}
12881259

1289-
pub enum DiagnosticOutput {
1290-
Default,
1291-
Raw(Box<dyn Write + Send>),
1292-
}
1293-
12941260
// JUSTIFICATION: literally session construction
12951261
#[allow(rustc::bad_opt_access)]
12961262
pub fn build_session(
12971263
sopts: config::Options,
12981264
local_crate_source_file: Option<PathBuf>,
12991265
bundle: Option<Lrc<rustc_errors::FluentBundle>>,
13001266
registry: rustc_errors::registry::Registry,
1301-
diagnostics_output: DiagnosticOutput,
13021267
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
13031268
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
13041269
target_override: Option<Target>,
@@ -1314,11 +1279,6 @@ pub fn build_session(
13141279
let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);
13151280
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
13161281

1317-
let write_dest = match diagnostics_output {
1318-
DiagnosticOutput::Default => None,
1319-
DiagnosticOutput::Raw(write) => Some(write),
1320-
};
1321-
13221282
let sysroot = match &sopts.maybe_sysroot {
13231283
Some(sysroot) => sysroot.clone(),
13241284
None => filesearch::get_or_default_sysroot(),
@@ -1351,8 +1311,7 @@ pub fn build_session(
13511311
rustc_errors::DEFAULT_LOCALE_RESOURCES,
13521312
sopts.unstable_opts.translate_directionality_markers,
13531313
);
1354-
let emitter =
1355-
default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle, write_dest);
1314+
let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle);
13561315

13571316
let span_diagnostic = rustc_errors::Handler::with_emitter_and_flags(
13581317
emitter,

Diff for: src/librustdoc/core.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
1414
use rustc_resolve as resolve;
1515
use rustc_session::config::{self, CrateType, ErrorOutputType};
1616
use rustc_session::lint;
17-
use rustc_session::DiagnosticOutput;
1817
use rustc_session::Session;
1918
use rustc_span::symbol::sym;
2019
use rustc_span::{source_map, Span, Symbol};
@@ -286,7 +285,6 @@ pub(crate) fn create_config(
286285
output_file: None,
287286
output_dir: None,
288287
file_loader: None,
289-
diagnostic_output: DiagnosticOutput::Default,
290288
lint_caps,
291289
parse_sess_created: None,
292290
register_lints: Some(Box::new(crate::lint::register_lints)),

Diff for: src/librustdoc/doctest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_parse::maybe_new_parser_from_source_str;
1414
use rustc_parse::parser::attr::InnerAttrPolicy;
1515
use rustc_session::config::{self, CrateType, ErrorOutputType};
1616
use rustc_session::parse::ParseSess;
17-
use rustc_session::{lint, DiagnosticOutput, Session};
17+
use rustc_session::{lint, Session};
1818
use rustc_span::edition::Edition;
1919
use rustc_span::source_map::SourceMap;
2020
use rustc_span::symbol::sym;
@@ -100,7 +100,6 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
100100
output_file: None,
101101
output_dir: None,
102102
file_loader: None,
103-
diagnostic_output: DiagnosticOutput::Default,
104103
lint_caps,
105104
parse_sess_created: None,
106105
register_lints: Some(Box::new(crate::lint::register_lints)),

Diff for: src/test/run-make-fulldeps/issue-19371/foo.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extern crate rustc_driver;
55
extern crate rustc_session;
66
extern crate rustc_span;
77

8-
use rustc_session::DiagnosticOutput;
98
use rustc_session::config::{Input, Options, OutputType, OutputTypes};
109
use rustc_interface::interface;
1110
use rustc_span::source_map::FileName;
@@ -55,7 +54,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
5554
output_file: Some(output),
5655
output_dir: None,
5756
file_loader: None,
58-
diagnostic_output: DiagnosticOutput::Default,
5957
lint_caps: Default::default(),
6058
parse_sess_created: None,
6159
register_lints: None,

0 commit comments

Comments
 (0)