Home Explore Blog CI



rustc

src/rustc-driver/getting-diagnostics.md
e0681eb77b429c1b58f5743f46d7667441731e86bbd210040000000300000361
# Example: Getting diagnostic through `rustc_interface`

The [`rustc_interface`] allows you to intercept diagnostics that would
otherwise be printed to stderr.

## Getting diagnostics

To get diagnostics from the compiler,
configure [`rustc_interface::Config`] to output diagnostic to a buffer,
and run [`rustc_hir_typeck::typeck`] for each item.

```rust
{{#include ../../examples/rustc-interface-getting-diagnostics.rs}}
```


Chunks
801f1117 (1st chunk of `src/rustc-driver/getting-diagnostics.md`)
Title: Getting Diagnostics Using `rustc_interface`
Summary
The `rustc_interface` enables interception of compiler diagnostics. To retrieve these diagnostics, configure `rustc_interface::Config` to output to a buffer and then execute `rustc_hir_typeck::typeck` for each item, as demonstrated in the example.