Skip to content

Commit 904fedf

Browse files
authored
Merge pull request rust-lang#2308 from rust-lang/update-examples
update rustc-{driver,interface} examples
2 parents 9448b79 + 1faf7ff commit 904fedf

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/doc/rustc-dev-guide/examples/rustc-driver-example.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-03-08
1+
// Tested with nightly-2025-03-28
22

33
#![feature(rustc_private)]
44

@@ -20,7 +20,7 @@ use std::path::Path;
2020
use std::sync::Arc;
2121

2222
use rustc_ast_pretty::pprust::item_to_string;
23-
use rustc_driver::{Compilation, run_compiler};
23+
use rustc_driver::{run_compiler, Compilation};
2424
use rustc_interface::interface::{Compiler, Config};
2525
use rustc_middle::ty::TyCtxt;
2626

@@ -71,13 +71,12 @@ 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_free_items(){
74+
for id in tcx.hir_free_items() {
7575
let item = &tcx.hir_item(id);
7676
match item.kind {
77-
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
78-
let name = item.ident;
77+
rustc_hir::ItemKind::Static(ident, ..) | rustc_hir::ItemKind::Fn { ident, .. } => {
7978
let ty = tcx.type_of(item.hir_id().owner.def_id);
80-
println!("{name:?}:\t{ty:?}")
79+
println!("{ident:?}:\t{ty:?}")
8180
}
8281
_ => (),
8382
}

src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-03-08
1+
// Tested with nightly-2025-03-28
22

33
#![feature(rustc_private)]
44

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

7272
fn after_analysis(&mut self, _compiler: &Compiler, tcx: TyCtxt<'_>) -> Compilation {
7373
// Iterate over the top-level items in the crate, looking for the main function.
74-
for id in tcx.hir_free_items(){
74+
for id in tcx.hir_free_items() {
7575
let item = &tcx.hir_item(id);
7676
// Use pattern-matching to find a specific node inside the main function.
7777
if let rustc_hir::ItemKind::Fn { body, .. } = item.kind {

src/doc/rustc-dev-guide/examples/rustc-interface-example.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-03-08
1+
// Tested with nightly-2025-03-28
22

33
#![feature(rustc_private)]
44

@@ -67,10 +67,10 @@ fn main() {
6767
for id in tcx.hir_free_items() {
6868
let item = tcx.hir_item(id);
6969
match item.kind {
70-
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
71-
let name = item.ident;
70+
rustc_hir::ItemKind::Static(ident, ..)
71+
| rustc_hir::ItemKind::Fn { ident, .. } => {
7272
let ty = tcx.type_of(item.hir_id().owner.def_id);
73-
println!("{name:?}:\t{ty:?}")
73+
println!("{ident:?}:\t{ty:?}")
7474
}
7575
_ => (),
7676
}

src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-03-08
1+
// Tested with nightly-2025-03-28
22

33
#![feature(rustc_private)]
44

0 commit comments

Comments
 (0)