Skip to content

Commit b0e3235

Browse files
authored
Rollup merge of rust-lang#130299 - vetleras:add_set_dcx, r=compiler-errors
Add set_dcx to ParseSess After [this](rust-lang#126623) PR was merged, it is no longer possible to inject one's own `Emitter` in the way [described in the Compiler Development Guide](https://rustc-dev-guide.rust-lang.org/rustc-driver-getting-diagnostics.html). The reason is that the `dcx` field in `ParseSess` is no longer public, so it is not possible to update the `dcx` field with a `DiagCtxt` that contains one's own `Emitter` in the `psess_created` callback in `rustc_interface::Config`. The only way I have found to insert my own `DiagCtxt` is by creating an entirely new `ParseSess` and replacing the old one. This is not a good solution as the original `ParseSess` contains fields I would like to keep. (In my case the problem is that I lose the `cfg` and `check-cfg` fields of the original.) The solution proposed in this PR is to add a `set_dcx` method to `ParseSess`. Per my limited understanding of the rustc codebase this should be fine as `set_dcx` requires a mutable reference to `ParseSess`, which is as far as I know only available in the `psess_created` callback (outside of `rustc_interface::run_compiler`). If this PR is accepted, I will create a new PR to update the aforementioned example in the Compiler Development Guide.
2 parents c5e0f9a + bde1f4d commit b0e3235

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compiler/rustc_session/src/parse.rs

+4
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,8 @@ impl ParseSess {
340340
pub fn dcx(&self) -> DiagCtxtHandle<'_> {
341341
self.dcx.handle()
342342
}
343+
344+
pub fn set_dcx(&mut self, dcx: DiagCtxt) {
345+
self.dcx = dcx;
346+
}
343347
}

0 commit comments

Comments
 (0)