Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update rustc-driver-interacting-with-the-ast.md #1930

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/rustc-driver-interacting-with-the-ast.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Example: Type checking through `rustc_interface`

`rustc_interface` allows you to interact with Rust code at various stages of compilation.
The [`rustc_interface`] 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 `global_ctxt` to get a `TyCtxt`.
To get the type of an expression, use the [`global_ctxt`] query to [get] a [`TyCtxt`].
Tbkhi marked this conversation as resolved.
Show resolved Hide resolved
The following was tested with <!-- date-check: jan 2024 --> `nightly-2024-01-19`:

```rust
{{#include ../examples/rustc-driver-interacting-with-the-ast.rs}}
```
Tbkhi marked this conversation as resolved.
Show resolved Hide resolved

[`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface
[get]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.GlobalCtxt.html#method.enter
[`TyCtxt`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html