Home Explore Blog CI



rustc

src/rustc-driver/interacting-with-the-ast.md
edd702d40970f00a58c8c9f792c0f8897c2fa04fdb8db43d0000000300000290
# 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}}
```

Chunks
0129b9dc (1st chunk of `src/rustc-driver/interacting-with-the-ast.md`)
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`.