Home Explore Blog CI



rustc

1st chunk of `src/rustc-driver/interacting-with-the-ast.md`
0129b9dc8ed2434c7125569a25787707e8a7dcae0060dc59000000010000015e
# Example: Type checking through `rustc_driver`

[`rustc_driver`] allows you to interact with Rust code at various stages of compilation.

## Getting the type of an expression

To get the type of an expression, use the [`after_analysis`] callback to get a [`TyCtxt`].

```rust
{{#include ../../examples/rustc-driver-interacting-with-the-ast.rs}}
```

Title: Type Checking with rustc_driver
Summary
The `rustc_driver` crate allows interaction with Rust code during compilation. To obtain the type of an expression, the `after_analysis` callback can be used to access a `TyCtxt`.