diff options
| author | Yang Lin <yanglin@smail.nju.edu.cn> | 2025-03-16 23:27:10 +0800 |
|---|---|---|
| committer | Yang Lin <yanglin@smail.nju.edu.cn> | 2025-03-16 23:27:10 +0800 |
| commit | a4b76e31f8f906e31256b2c8f696e39b2ee36c41 (patch) | |
| tree | 6f2bc8e8cf2ed8a77ddc4a89c111ddbc0e263a19 /src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs | |
| parent | b30d1970ab99dd31e3ba30bd6dcf815b3fc75aee (diff) | |
| download | rust-a4b76e31f8f906e31256b2c8f696e39b2ee36c41.tar.gz rust-a4b76e31f8f906e31256b2c8f696e39b2ee36c41.zip | |
Adapt to rust-lang/rust#136466:
Start removing `rustc_middle::hir::map::Map` Following commit f86f7ad from pull request #136466 in the Rust project (https://github.com/rust-lang/rust), some methods in `Map` were moved to `TyCtxt`. This update reimplements `rustc-drive-example.rs`, `rustc-driver-interacting-with-the-ast.rs`, and `rustc-interface-example.rs` using the new versions of these methods, ensuring compatibility with the nightly-2025-03-08 toolchain.
Diffstat (limited to 'src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs')
| -rw-r--r-- | src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs b/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs index 3270c722e07..2a43ba476e1 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs @@ -1,4 +1,4 @@ -// Tested with nightly-2025-02-13 +// Tested with nightly-2025-03-08 #![feature(rustc_private)] @@ -70,11 +70,9 @@ impl rustc_driver::Callbacks for MyCallbacks { } fn after_analysis(&mut self, _compiler: &Compiler, tcx: TyCtxt<'_>) -> Compilation { - // Every compilation contains a single crate. - let hir_krate = tcx.hir(); // Iterate over the top-level items in the crate, looking for the main function. - for id in hir_krate.items() { - let item = hir_krate.item(id); + for id in tcx.hir_free_items(){ + let item = &tcx.hir_item(id); // Use pattern-matching to find a specific node inside the main function. if let rustc_hir::ItemKind::Fn { body, .. } = item.kind { let expr = &tcx.hir_body(body).value; |
