diff options
| author | The Miri Cronjob Bot <miri@cron.bot> | 2025-04-07 05:24:10 +0000 |
|---|---|---|
| committer | The Miri Cronjob Bot <miri@cron.bot> | 2025-04-07 05:24:10 +0000 |
| commit | 2eb7791a1bc72b5d2357d0ee8be7e1ece5dc26c5 (patch) | |
| tree | 5f316fbcf48a556c06e14f8b34c46880f5b4c2aa /src/doc/rustc-dev-guide/examples/rustc-driver-example.rs | |
| parent | fa06e723adb8ad4a4cc995b2fccfccc7caf80bff (diff) | |
| parent | 25a615bf829b9f6d6f22da537e3851043f92e5f2 (diff) | |
| download | rust-2eb7791a1bc72b5d2357d0ee8be7e1ece5dc26c5.tar.gz rust-2eb7791a1bc72b5d2357d0ee8be7e1ece5dc26c5.zip | |
Merge from rustc
Diffstat (limited to 'src/doc/rustc-dev-guide/examples/rustc-driver-example.rs')
| -rw-r--r-- | src/doc/rustc-dev-guide/examples/rustc-driver-example.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs index 984bd3e37ae..db6ac185785 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs @@ -1,4 +1,4 @@ -// Tested with nightly-2025-02-13 +// Tested with nightly-2025-03-28 #![feature(rustc_private)] @@ -34,9 +34,9 @@ impl rustc_span::source_map::FileLoader for MyFileLoader { fn read_file(&self, path: &Path) -> io::Result<String> { if path == Path::new("main.rs") { Ok(r#" +static MESSAGE: &str = "Hello, World!"; fn main() { - let message = "Hello, World!"; - println!("{message}"); + println!("{MESSAGE}"); } "# .to_string()) @@ -71,14 +71,12 @@ impl rustc_driver::Callbacks for MyCallbacks { 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; + rustc_hir::ItemKind::Static(ident, ..) | rustc_hir::ItemKind::Fn { ident, .. } => { let ty = tcx.type_of(item.hir_id().owner.def_id); - println!("{name:?}:\t{ty:?}") + println!("{ident:?}:\t{ty:?}") } _ => (), } |
