Using the rustc_interface crate

It used to be possible to give your own emitter, but it seems that it is now hard coded: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_session/session.rs.html#1004. You could try to set Config.diagnostic_output to DiagnosticOutput::Raw and set the error format to json to get the errors in json format.

It's kinda strange that in order to tap into the error stream, I have to get it in JSON format and re-parse it. Ideally there would be a way to intercept the stream of typed events before they get serialized to JSON. Should I create an issue in the rustc repo?

Yeah, it used to be possible to get the error by passing your own error emitter. Creating an issue makes sense.

OK, I've made the issue: https://github.com/rust-lang/rust/issues/71770

I'd be happy to work on this, would just like some guidance from rust maintainers on the right approach.

@georgewfraser I would imagine that zulip might be the best place to ask for such guidance: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp

Perhaps ping Zoxc there?

OK, I've made another docs example, this time of how to intercept diagnostics: https://github.com/rust-lang/rustc-dev-guide/pull/693

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.