# Using the rustc\_interface crate

**URL:** <https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982>\
**Category:** tools and infrastructure\
**Created:** [March 15, 2020, 6:10pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982 "2020-03-15T18:10:28Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [April 27, 2020, 1:31pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/21 "2020-04-27T13:31:36Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![georgewfraser](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@georgewfraser](https://internals.rust-lang.org/u/georgewfraser)\
**Post date:** [April 27, 2020, 10:09pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/22 "2020-04-27T22:09:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [April 28, 2020, 8:01am UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/23 "2020-04-28T08:01:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![georgewfraser](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@georgewfraser](https://internals.rust-lang.org/u/georgewfraser)\
**Post date:** [May 1, 2020, 8:12pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/24 "2020-05-01T20:12:41Z")

</div>

OK, I've made the issue: [https://github.com/rust-lang/rust/issues/71770](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.

---

<div class="post-metadata">

**Author:** ![mark-i-m](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mark-i-m/32/3167_2.png) [@mark-i-m](https://internals.rust-lang.org/u/mark-i-m)\
**Post date:** [May 1, 2020, 10:22pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/25 "2020-05-01T22:22:53Z")

</div>

@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](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp)

Perhaps ping Zoxc there?

---

<div class="post-metadata">

**Author:** ![georgewfraser](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@georgewfraser](https://internals.rust-lang.org/u/georgewfraser)\
**Post date:** [May 2, 2020, 9:51pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/26 "2020-05-02T21:51:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [July 31, 2020, 9:53pm UTC](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982/27 "2020-07-31T21:53:41Z")

</div>

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

[Previous page](https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982.md?page=1)
