Skip to content

Commit 2763ca5

Browse files
committed
Auto merge of rust-lang#116619 - nnethercote:rustc_driver_impl, r=compiler-errors
Streamline `rustc_driver_impl` pretty-printing. This PR simplifies a lot of unnecessary structure in `rustc_driver_impl/src/pretty.rs`. It removes some traits and functions, simplifies some structs, renames some things for increased consistency, and eliminates some boilerplate code. Overall it cuts more than 150 lines of code. r? `@compiler-errors`
2 parents 130ff8c + 2b4c338 commit 2763ca5

File tree

3 files changed

+150
-305
lines changed

3 files changed

+150
-305
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#![cfg_attr(not(bootstrap), doc(rust_logo))]
99
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
1010
#![cfg_attr(not(bootstrap), allow(internal_features))]
11-
#![feature(lazy_cell)]
1211
#![feature(decl_macro)]
13-
#![feature(panic_update_hook)]
12+
#![feature(lazy_cell)]
1413
#![feature(let_chains)]
14+
#![feature(panic_update_hook)]
1515
#![recursion_limit = "256"]
1616
#![allow(rustc::potential_query_instability)]
1717
#![deny(rustc::untranslatable_diagnostic)]
@@ -395,7 +395,7 @@ fn run_compiler(
395395
if ppm.needs_ast_map() {
396396
queries.global_ctxt()?.enter(|tcx| {
397397
tcx.ensure().early_lint_checks(());
398-
pretty::print_after_hir_lowering(tcx, *ppm);
398+
pretty::print(sess, *ppm, pretty::PrintExtra::NeedsAstMap { tcx });
399399
Ok(())
400400
})?;
401401

@@ -404,7 +404,7 @@ fn run_compiler(
404404
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
405405
} else {
406406
let krate = queries.parse()?.steal();
407-
pretty::print_after_parsing(sess, &krate, *ppm);
407+
pretty::print(sess, *ppm, pretty::PrintExtra::AfterParsing { krate });
408408
}
409409
trace!("finished pretty-printing");
410410
return early_exit();
@@ -545,7 +545,7 @@ pub enum Compilation {
545545
}
546546

547547
impl Compilation {
548-
pub fn and_then<F: FnOnce() -> Compilation>(self, next: F) -> Compilation {
548+
fn and_then<F: FnOnce() -> Compilation>(self, next: F) -> Compilation {
549549
match self {
550550
Compilation::Stop => Compilation::Stop,
551551
Compilation::Continue => next(),
@@ -657,7 +657,7 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
657657
}
658658
}
659659

660-
pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Compilation {
660+
fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Compilation {
661661
if sess.opts.unstable_opts.link_only {
662662
if let Input::File(file) = &sess.io.input {
663663
let outputs = compiler.build_output_filenames(sess, &[]);
@@ -698,7 +698,7 @@ pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Comp
698698
}
699699
}
700700

701-
pub fn list_metadata(
701+
fn list_metadata(
702702
handler: &EarlyErrorHandler,
703703
sess: &Session,
704704
metadata_loader: &dyn MetadataLoader,
@@ -1184,7 +1184,7 @@ fn print_flag_list<T>(
11841184
///
11851185
/// So with all that in mind, the comments below have some more detail about the
11861186
/// contortions done here to get things to work out correctly.
1187-
pub fn handle_options(handler: &EarlyErrorHandler, args: &[String]) -> Option<getopts::Matches> {
1187+
fn handle_options(handler: &EarlyErrorHandler, args: &[String]) -> Option<getopts::Matches> {
11881188
if args.is_empty() {
11891189
// user did not write `-v` nor `-Z unstable-options`, so do not
11901190
// include that extra information.
@@ -1283,9 +1283,9 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
12831283
}
12841284
}
12851285

1286-
pub static ICE_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
1286+
static ICE_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
12871287

1288-
pub fn ice_path() -> &'static Option<PathBuf> {
1288+
fn ice_path() -> &'static Option<PathBuf> {
12891289
ICE_PATH.get_or_init(|| {
12901290
if !rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build() {
12911291
return None;
@@ -1394,7 +1394,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13941394
///
13951395
/// When `install_ice_hook` is called, this function will be called as the panic
13961396
/// hook.
1397-
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info: fn(&Handler)) {
1397+
fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info: fn(&Handler)) {
13981398
let fallback_bundle =
13991399
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
14001400
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(

0 commit comments

Comments
 (0)