Skip to content

Commit 42174f0

Browse files
committed
impl Default for EarlyDiagCtxt
for small rustc_driver programs, most of their imports will currently be related to diagnostics. this change simplifiers their code so it's more clear what in the driver is modified from the default. this is especially important for external drivers which are out of tree and not updated in response to breaking changes. for these drivers, each import is a liability for future code, since it can be broken when refactors happen. here is an example driver which is simplified by these changes: ``` diff --git a/src/main.rs b/src/main.rs index f81aa3e..11e5f18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,8 @@ #![feature(rustc_private)] extern crate rustc_driver; extern crate rustc_interface; -extern crate rustc_errors; -extern crate rustc_session; use rustc_driver::Callbacks; -use rustc_errors::{emitter::HumanReadableErrorType, ColorConfig}; use rustc_interface::interface; -use rustc_session::config::ErrorOutputType; -use rustc_session::EarlyDiagCtxt; struct DisableSafetyChecks; @@ -26,11 +18,7 @@ fn main() { "https://github.com/jyn514/jyn514.github.io/issues/new", |_| (), ); - let handler = EarlyDiagCtxt::new(ErrorOutputType::HumanReadable( - HumanReadableErrorType::Default, - ColorConfig::Auto, - )); - rustc_driver::init_rustc_env_logger(&handler); + rustc_driver::init_rustc_env_logger(&Default::default()); std::process::exit(rustc_driver::catch_with_exit_code(move || { let args: Vec<String> = std::env::args().collect(); rustc_driver::RunCompiler::new(&args, &mut DisableSafetyChecks).run() ```
1 parent bd36e69 commit 42174f0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,12 @@ pub struct EarlyDiagCtxt {
13581358
dcx: DiagCtxt,
13591359
}
13601360

1361+
impl Default for EarlyDiagCtxt {
1362+
fn default() -> Self {
1363+
Self::new(ErrorOutputType::default())
1364+
}
1365+
}
1366+
13611367
impl EarlyDiagCtxt {
13621368
pub fn new(output: ErrorOutputType) -> Self {
13631369
let emitter = mk_emitter(output);

0 commit comments

Comments
 (0)