Skip to content

Commit

Permalink
update rustc-driver-interacting-with-the-ast.md (rust-lang#1930)
Browse files Browse the repository at this point in the history
* adding links

* Update src/rustc-driver-interacting-with-the-ast.md

Co-authored-by: Tshepang Mbambo <[email protected]>

* redo links and formatting

* Update rustc-driver-interacting-with-the-ast.md

---------

Co-authored-by: Tshepang Mbambo <[email protected]>
  • Loading branch information
Tbkhi and tshepang authored Mar 11, 2024
1 parent aa2a0d1 commit 8a5d647
Showing 1 changed file with 6 additions and 2 deletions.
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`].
The following was tested with <!-- date-check: jan 2024 --> `nightly-2024-01-19`:

```rust
{{#include ../examples/rustc-driver-interacting-with-the-ast.rs}}
```
[get]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.GlobalCtxt.html#method.enter
[`global_ctxt`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/queries/struct.Queries.html#method.global_ctxt
[`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface
[`TyCtxt`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html

0 comments on commit 8a5d647

Please sign in to comment.