Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Default for EarlyDiagCtxt #133757

Merged
merged 1 commit into from
Dec 2, 2024
Merged

impl Default for EarlyDiagCtxt #133757

merged 1 commit into from
Dec 2, 2024

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Dec 2, 2024

for small rustc_driver programs, most of their imports will currently be related to diagnostics. this change simplifies 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()

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()
```
@rustbot
Copy link
Collaborator

rustbot commented Dec 2, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 2, 2024
@compiler-errors
Copy link
Member

r? compiler-errors @bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 2, 2024

📌 Commit 42174f0 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 2, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 2, 2024
…llaumeGomez

Rollup of 13 pull requests

Successful merges:

 - rust-lang#133603 (Eliminate magic numbers from expression precedence)
 - rust-lang#133715 (rustdoc-json: Include safety of `static`s)
 - rust-lang#133721 (rustdoc-json: Add test for `impl Trait for dyn Trait`)
 - rust-lang#133725 (Remove `//@ compare-output-lines-by-subset`)
 - rust-lang#133730 (Add pretty-printer parenthesis insertion test)
 - rust-lang#133736 (Add `needs-target-has-atomic` directive)
 - rust-lang#133739 (Re-add myself to rotation)
 - rust-lang#133743 (Fix docs for `<[T]>::as_array`.)
 - rust-lang#133744 (Fix typo README.md)
 - rust-lang#133745 (Remove static HashSet for default IDs list)
 - rust-lang#133749 (mir validator: don't store mir phase)
 - rust-lang#133751 (remove `Ty::is_copy_modulo_regions`)
 - rust-lang#133757 (`impl Default for EarlyDiagCtxt`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 586591f into rust-lang:master Dec 2, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 2, 2024
Rollup merge of rust-lang#133757 - jyn514:error-handler, r=compiler-errors

`impl Default for EarlyDiagCtxt`

for small rustc_driver programs, most of their imports will currently be related to diagnostics. this change simplifies 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
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()
```
@rustbot rustbot added this to the 1.85.0 milestone Dec 2, 2024
@jyn514 jyn514 deleted the error-handler branch December 3, 2024 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants