Skip to content

Commit

Permalink
Unrolled build for rust-lang#130299
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rust-timer authored Sep 13, 2024
2 parents 0307e40 + bde1f4d commit 9979924
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,8 @@ impl ParseSess {
pub fn dcx(&self) -> DiagCtxtHandle<'_> {
self.dcx.handle()
}

pub fn set_dcx(&mut self, dcx: DiagCtxt) {
self.dcx = dcx;
}
}

0 comments on commit 9979924

Please sign in to comment.