Home Explore Blog CI



rustc

1st chunk of `src/rustc-driver/getting-diagnostics.md`
801f111732e478b7678776a095f60a5011f5aac12e12ab2300000001000001ac
# 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}}
```


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.