diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-05-02 08:19:20 +0900 |
|---|---|---|
| committer | Tshepang Mbambo <tshepang@gmail.com> | 2022-05-30 13:57:16 +0200 |
| commit | 93771d84e0f5113a3ff8418541e34eca05858a8f (patch) | |
| tree | 9de8a0874d02563a05b863998dc0df3e9ff1a859 /src/doc/rustc-dev-guide/examples | |
| parent | 637f3f2af8524b91f7c159c455166496c51d1515 (diff) | |
Update rustc-driver related examples
Diffstat (limited to 'src/doc/rustc-dev-guide/examples')
3 files changed, 11 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 7177a286892..8a5d880fab2 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs @@ -1,9 +1,9 @@ #![feature(rustc_private)] // NOTE: For the example to compile, you will need to first run the following: -// rustup component add rustc-dev +// rustup component add rustc-dev llvm-tools-preview -// version: 1.61.0-nightly (68369a041 2022-02-22) +// version: 1.62.0-nightly (7c4b47696 2022-04-30) extern crate rustc_error_codes; extern crate rustc_errors; @@ -72,7 +72,8 @@ fn main() { println!("{:#?}", parse); // Analyze the program and inspect the types of definitions. queries.global_ctxt().unwrap().take().enter(|tcx| { - for item in tcx.hir().items() { + for id in tcx.hir().items() { + let item = tcx.hir().item(id); match item.kind { rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => { let name = item.ident; diff --git a/src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs b/src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs index c25695dd020..3bb0d545041 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs @@ -1,9 +1,9 @@ #![feature(rustc_private)] // NOTE: For the example to compile, you will need to first run the following: -// rustup component add rustc-dev +// rustup component add rustc-dev llvm-tools-preview -// version: 1.61.0-nightly (68369a041 2022-02-22) +// version: 1.62.0-nightly (7c4b47696 2022-04-30) extern crate rustc_error_codes; extern crate rustc_errors; 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 c942ac32442..a0110f82d92 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,9 +1,9 @@ #![feature(rustc_private)] // NOTE: For the example to compile, you will need to first run the following: -// rustup component add rustc-dev llvm-tools-preview +// rustup component add rustc-dev llvm-tools-preview -// version: 1.61.0-nightly (68369a041 2022-02-22) +// version: 1.62.0-nightly (7c4b47696 2022-04-30) extern crate rustc_ast_pretty; extern crate rustc_error_codes; @@ -66,7 +66,8 @@ fn main() { // 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 item in hir_krate.items() { + for id in hir_krate.items() { + let item = hir_krate.item(id); // Use pattern-matching to find a specific node inside the main function. if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind { let expr = &tcx.hir().body(body_id).value; @@ -76,7 +77,7 @@ fn main() { let hir_id = expr.hir_id; // hir_id identifies the string "Hello, world!" let def_id = tcx.hir().local_def_id(item.hir_id()); // def_id identifies the main function let ty = tcx.typeck(def_id).node_type(hir_id); - println!("{:?}: {:?}", expr, ty); // prints expr(HirId { owner: DefIndex(3), local_id: 4 }: "Hello, world!"): &'static str + println!("{:?}: {:?}", expr, ty); } } } |
