Skip to content

Commit 971366b

Browse files
committed
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.
1 parent 077fae6 commit 971366b

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

examples/rustc-driver-example.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-02-13
1+
// Tested with nightly-2025-03-08
22

33
#![feature(rustc_private)]
44

@@ -71,9 +71,8 @@ impl rustc_driver::Callbacks for MyCallbacks {
7171

7272
fn after_analysis(&mut self, _compiler: &Compiler, tcx: TyCtxt<'_>) -> Compilation {
7373
// Analyze the program and inspect the types of definitions.
74-
for id in tcx.hir().items() {
75-
let hir = tcx.hir();
76-
let item = hir.item(id);
74+
for id in tcx.hir_free_items(){
75+
let item = &tcx.hir_item(id);
7776
match item.kind {
7877
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
7978
let name = item.ident;

examples/rustc-driver-interacting-with-the-ast.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-02-13
1+
// Tested with nightly-2025-03-08
22

33
#![feature(rustc_private)]
44

@@ -70,11 +70,9 @@ impl rustc_driver::Callbacks for MyCallbacks {
7070
}
7171

7272
fn after_analysis(&mut self, _compiler: &Compiler, tcx: TyCtxt<'_>) -> Compilation {
73-
// Every compilation contains a single crate.
74-
let hir_krate = tcx.hir();
7573
// Iterate over the top-level items in the crate, looking for the main function.
76-
for id in hir_krate.items() {
77-
let item = hir_krate.item(id);
74+
for id in tcx.hir_free_items(){
75+
let item = &tcx.hir_item(id);
7876
// Use pattern-matching to find a specific node inside the main function.
7977
if let rustc_hir::ItemKind::Fn { body, .. } = item.kind {
8078
let expr = &tcx.hir_body(body).value;

examples/rustc-interface-example.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-02-13
1+
// Tested with nightly-2025-03-08
22

33
#![feature(rustc_private)]
44

@@ -64,9 +64,8 @@ fn main() {
6464
println!("{krate:?}");
6565
// Analyze the program and inspect the types of definitions.
6666
rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
67-
for id in tcx.hir().items() {
68-
let hir = tcx.hir();
69-
let item = hir.item(id);
67+
for id in tcx.hir_free_items() {
68+
let item = tcx.hir_item(id);
7069
match item.kind {
7170
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
7271
let name = item.ident;

0 commit comments

Comments
 (0)