Skip to content

Commit d58e372

Browse files
committed
Rename many EarlyDiagCtxt arguments.
1 parent f422dca commit d58e372

File tree

10 files changed

+196
-196
lines changed

10 files changed

+196
-196
lines changed

compiler/rustc_driver_impl/src/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
2323
/// **Note:** This function doesn't interpret argument 0 in any special way.
2424
/// If this function is intended to be used with command line arguments,
2525
/// `argv[0]` must be removed prior to calling it manually.
26-
pub fn arg_expand_all(handler: &EarlyDiagCtxt, at_args: &[String]) -> Vec<String> {
26+
pub fn arg_expand_all(early_dcx: &EarlyDiagCtxt, at_args: &[String]) -> Vec<String> {
2727
let mut args = Vec::new();
2828
for arg in at_args {
2929
match arg_expand(arg.clone()) {
3030
Ok(arg) => args.extend(arg),
31-
Err(err) => handler.early_error(format!("Failed to load argument file: {err}")),
31+
Err(err) => early_dcx.early_error(format!("Failed to load argument file: {err}")),
3232
}
3333
}
3434
args

compiler/rustc_driver_impl/src/lib.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileNa
495495

496496
// Extract input (string or file and optional path) from matches.
497497
fn make_input(
498-
handler: &EarlyDiagCtxt,
498+
early_dcx: &EarlyDiagCtxt,
499499
free_matches: &[String],
500500
) -> Result<Option<Input>, ErrorGuaranteed> {
501501
if free_matches.len() == 1 {
@@ -505,7 +505,7 @@ fn make_input(
505505
if io::stdin().read_to_string(&mut src).is_err() {
506506
// Immediately stop compilation if there was an issue reading
507507
// the input (for example if the input stream is not UTF-8).
508-
let reported = handler.early_error_no_abort(
508+
let reported = early_dcx.early_error_no_abort(
509509
"couldn't read from stdin, as it did not contain valid UTF-8",
510510
);
511511
return Err(reported);
@@ -537,7 +537,7 @@ pub enum Compilation {
537537
Continue,
538538
}
539539

540-
fn handle_explain(handler: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) {
540+
fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) {
541541
let upper_cased_code = code.to_ascii_uppercase();
542542
let normalised =
543543
if upper_cased_code.starts_with('E') { upper_cased_code } else { format!("E{code:0>4}") };
@@ -567,7 +567,7 @@ fn handle_explain(handler: &EarlyDiagCtxt, registry: Registry, code: &str, color
567567
}
568568
}
569569
Err(InvalidErrorCode) => {
570-
handler.early_error(format!("{code} is not a valid error code"));
570+
early_dcx.early_error(format!("{code} is not a valid error code"));
571571
}
572572
}
573573
}
@@ -669,7 +669,7 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
669669
}
670670
}
671671

672-
fn list_metadata(handler: &EarlyDiagCtxt, sess: &Session, metadata_loader: &dyn MetadataLoader) {
672+
fn list_metadata(early_dcx: &EarlyDiagCtxt, sess: &Session, metadata_loader: &dyn MetadataLoader) {
673673
match sess.io.input {
674674
Input::File(ref ifile) => {
675675
let path = &(*ifile);
@@ -685,13 +685,13 @@ fn list_metadata(handler: &EarlyDiagCtxt, sess: &Session, metadata_loader: &dyn
685685
safe_println!("{}", String::from_utf8(v).unwrap());
686686
}
687687
Input::Str { .. } => {
688-
handler.early_error("cannot list metadata for stdin");
688+
early_dcx.early_error("cannot list metadata for stdin");
689689
}
690690
}
691691
}
692692

693693
fn print_crate_info(
694-
handler: &EarlyDiagCtxt,
694+
early_dcx: &EarlyDiagCtxt,
695695
codegen_backend: &dyn CodegenBackend,
696696
sess: &Session,
697697
parse_attrs: bool,
@@ -838,7 +838,7 @@ fn print_crate_info(
838838
.expect("unknown Apple target OS");
839839
println_info!("deployment_target={}", format!("{major}.{minor}"))
840840
} else {
841-
handler
841+
early_dcx
842842
.early_error("only Apple targets currently support deployment version info")
843843
}
844844
}
@@ -869,7 +869,7 @@ pub macro version($handler: expr, $binary: literal, $matches: expr) {
869869

870870
#[doc(hidden)] // use the macro instead
871871
pub fn version_at_macro_invocation(
872-
handler: &EarlyDiagCtxt,
872+
early_dcx: &EarlyDiagCtxt,
873873
binary: &str,
874874
matches: &getopts::Matches,
875875
version: &str,
@@ -890,7 +890,7 @@ pub fn version_at_macro_invocation(
890890

891891
let debug_flags = matches.opt_strs("Z");
892892
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
893-
get_codegen_backend(handler, &None, backend_name).print_version();
893+
get_codegen_backend(early_dcx, &None, backend_name).print_version();
894894
}
895895
}
896896

@@ -1068,7 +1068,7 @@ Available lint options:
10681068
/// Show help for flag categories shared between rustdoc and rustc.
10691069
///
10701070
/// Returns whether a help option was printed.
1071-
pub fn describe_flag_categories(handler: &EarlyDiagCtxt, matches: &Matches) -> bool {
1071+
pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) -> bool {
10721072
// Handle the special case of -Wall.
10731073
let wall = matches.opt_strs("W");
10741074
if wall.iter().any(|x| *x == "all") {
@@ -1090,12 +1090,12 @@ pub fn describe_flag_categories(handler: &EarlyDiagCtxt, matches: &Matches) -> b
10901090
}
10911091

10921092
if cg_flags.iter().any(|x| *x == "no-stack-check") {
1093-
handler.early_warn("the --no-stack-check flag is deprecated and does nothing");
1093+
early_dcx.early_warn("the --no-stack-check flag is deprecated and does nothing");
10941094
}
10951095

10961096
if cg_flags.iter().any(|x| *x == "passes=list") {
10971097
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
1098-
get_codegen_backend(handler, &None, backend_name).print_passes();
1098+
get_codegen_backend(early_dcx, &None, backend_name).print_passes();
10991099
return true;
11001100
}
11011101

@@ -1156,7 +1156,7 @@ fn print_flag_list<T>(
11561156
/// This does not need to be `pub` for rustc itself, but @chaosite needs it to
11571157
/// be public when using rustc as a library, see
11581158
/// <https://github.com/rust-lang/rust/commit/2b4c33817a5aaecabf4c6598d41e190080ec119e>
1159-
pub fn handle_options(handler: &EarlyDiagCtxt, args: &[String]) -> Option<getopts::Matches> {
1159+
pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<getopts::Matches> {
11601160
if args.is_empty() {
11611161
// user did not write `-v` nor `-Z unstable-options`, so do not
11621162
// include that extra information.
@@ -1182,7 +1182,7 @@ pub fn handle_options(handler: &EarlyDiagCtxt, args: &[String]) -> Option<getopt
11821182
.map(|(flag, _)| format!("{e}. Did you mean `-{flag} {opt}`?")),
11831183
_ => None,
11841184
};
1185-
handler.early_error(msg.unwrap_or_else(|| e.to_string()));
1185+
early_dcx.early_error(msg.unwrap_or_else(|| e.to_string()));
11861186
});
11871187

11881188
// For all options we just parsed, we check a few aspects:
@@ -1196,7 +1196,7 @@ pub fn handle_options(handler: &EarlyDiagCtxt, args: &[String]) -> Option<getopt
11961196
// we're good to go.
11971197
// * Otherwise, if we're an unstable option then we generate an error
11981198
// (unstable option being used on stable)
1199-
nightly_options::check_nightly_options(handler, &matches, &config::rustc_optgroups());
1199+
nightly_options::check_nightly_options(early_dcx, &matches, &config::rustc_optgroups());
12001200

12011201
if matches.opt_present("h") || matches.opt_present("help") {
12021202
// Only show unstable options in --help if we accept unstable options.
@@ -1206,12 +1206,12 @@ pub fn handle_options(handler: &EarlyDiagCtxt, args: &[String]) -> Option<getopt
12061206
return None;
12071207
}
12081208

1209-
if describe_flag_categories(handler, &matches) {
1209+
if describe_flag_categories(early_dcx, &matches) {
12101210
return None;
12111211
}
12121212

12131213
if matches.opt_present("version") {
1214-
version!(handler, "rustc", &matches);
1214+
version!(early_dcx, "rustc", &matches);
12151215
return None;
12161216
}
12171217

@@ -1472,16 +1472,16 @@ fn report_ice(
14721472

14731473
/// This allows tools to enable rust logging without having to magically match rustc's
14741474
/// tracing crate version.
1475-
pub fn init_rustc_env_logger(handler: &EarlyDiagCtxt) {
1476-
init_logger(handler, rustc_log::LoggerConfig::from_env("RUSTC_LOG"));
1475+
pub fn init_rustc_env_logger(early_dcx: &EarlyDiagCtxt) {
1476+
init_logger(early_dcx, rustc_log::LoggerConfig::from_env("RUSTC_LOG"));
14771477
}
14781478

14791479
/// This allows tools to enable rust logging without having to magically match rustc's
14801480
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose
14811481
/// the values directly rather than having to set an environment variable.
1482-
pub fn init_logger(handler: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
1482+
pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
14831483
if let Err(error) = rustc_log::init_logger(cfg) {
1484-
handler.early_error(error.to_string());
1484+
early_dcx.early_error(error.to_string());
14851485
}
14861486
}
14871487

compiler/rustc_interface/src/util.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
161161
})
162162
}
163163

164-
fn load_backend_from_dylib(handler: &EarlyDiagCtxt, path: &Path) -> MakeBackendFn {
164+
fn load_backend_from_dylib(early_dcx: &EarlyDiagCtxt, path: &Path) -> MakeBackendFn {
165165
let lib = unsafe { Library::new(path) }.unwrap_or_else(|err| {
166166
let err = format!("couldn't load codegen backend {path:?}: {err}");
167-
handler.early_error(err);
167+
early_dcx.early_error(err);
168168
});
169169

170170
let backend_sym = unsafe { lib.get::<MakeBackendFn>(b"__rustc_codegen_backend") }
171171
.unwrap_or_else(|e| {
172172
let err = format!("couldn't load codegen backend: {e}");
173-
handler.early_error(err);
173+
early_dcx.early_error(err);
174174
});
175175

176176
// Intentionally leak the dynamic library. We can't ever unload it
@@ -185,7 +185,7 @@ fn load_backend_from_dylib(handler: &EarlyDiagCtxt, path: &Path) -> MakeBackendF
185185
///
186186
/// A name of `None` indicates that the default backend should be used.
187187
pub fn get_codegen_backend(
188-
handler: &EarlyDiagCtxt,
188+
early_dcx: &EarlyDiagCtxt,
189189
maybe_sysroot: &Option<PathBuf>,
190190
backend_name: Option<&str>,
191191
) -> Box<dyn CodegenBackend> {
@@ -196,11 +196,11 @@ pub fn get_codegen_backend(
196196

197197
match backend_name.unwrap_or(default_codegen_backend) {
198198
filename if filename.contains('.') => {
199-
load_backend_from_dylib(handler, filename.as_ref())
199+
load_backend_from_dylib(early_dcx, filename.as_ref())
200200
}
201201
#[cfg(feature = "llvm")]
202202
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,
203-
backend_name => get_codegen_sysroot(handler, maybe_sysroot, backend_name),
203+
backend_name => get_codegen_sysroot(early_dcx, maybe_sysroot, backend_name),
204204
}
205205
});
206206

@@ -233,7 +233,7 @@ fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {
233233
}
234234

235235
fn get_codegen_sysroot(
236-
handler: &EarlyDiagCtxt,
236+
early_dcx: &EarlyDiagCtxt,
237237
maybe_sysroot: &Option<PathBuf>,
238238
backend_name: &str,
239239
) -> MakeBackendFn {
@@ -271,7 +271,7 @@ fn get_codegen_sysroot(
271271
"failed to find a `codegen-backends` folder \
272272
in the sysroot candidates:\n* {candidates}"
273273
);
274-
handler.early_error(err);
274+
early_dcx.early_error(err);
275275
});
276276
info!("probing {} for a codegen backend", sysroot.display());
277277

@@ -282,7 +282,7 @@ fn get_codegen_sysroot(
282282
sysroot.display(),
283283
e
284284
);
285-
handler.early_error(err);
285+
early_dcx.early_error(err);
286286
});
287287

288288
let mut file: Option<PathBuf> = None;
@@ -310,16 +310,16 @@ fn get_codegen_sysroot(
310310
prev.display(),
311311
path.display()
312312
);
313-
handler.early_error(err);
313+
early_dcx.early_error(err);
314314
}
315315
file = Some(path.clone());
316316
}
317317

318318
match file {
319-
Some(ref s) => load_backend_from_dylib(handler, s),
319+
Some(ref s) => load_backend_from_dylib(early_dcx, s),
320320
None => {
321321
let err = format!("unsupported builtin codegen backend `{backend_name}`");
322-
handler.early_error(err);
322+
early_dcx.early_error(err);
323323
}
324324
}
325325
}

0 commit comments

Comments
 (0)