mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Tested with nightly-2025-02-13
|
||||
// Tested with nightly-2025-03-08
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
@@ -71,9 +71,8 @@ fn after_crate_root_parsing(
|
||||
|
||||
fn after_analysis(&mut self, _compiler: &Compiler, tcx: TyCtxt<'_>) -> Compilation {
|
||||
// Analyze the program and inspect the types of definitions.
|
||||
for id in tcx.hir().items() {
|
||||
let hir = tcx.hir();
|
||||
let item = hir.item(id);
|
||||
for id in tcx.hir_free_items(){
|
||||
let item = &tcx.hir_item(id);
|
||||
match item.kind {
|
||||
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
|
||||
let name = item.ident;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Tested with nightly-2025-02-13
|
||||
// Tested with nightly-2025-03-08
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
@@ -70,11 +70,9 @@ fn after_crate_root_parsing(
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Tested with nightly-2025-02-13
|
||||
// Tested with nightly-2025-03-08
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
@@ -64,9 +64,8 @@ fn main() {
|
||||
println!("{krate:?}");
|
||||
// Analyze the program and inspect the types of definitions.
|
||||
rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
||||
for id in tcx.hir().items() {
|
||||
let hir = tcx.hir();
|
||||
let item = hir.item(id);
|
||||
for id in tcx.hir_free_items() {
|
||||
let item = tcx.hir_item(id);
|
||||
match item.kind {
|
||||
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
|
||||
let name = item.ident;
|
||||
|
||||
Reference in New Issue
Block a user