about summary refs log tree commit diff
path: root/src/doc/rustc-dev-guide
diff options
context:
space:
mode:
authorHiroki Fujino <hirokifujino0108@gmail.com>2023-02-09 10:56:06 +0100
committerGitHub <noreply@github.com>2023-02-09 18:56:06 +0900
commitc1658f32a0eeef823559ae29c7ad9dcd6fdbb0bb (patch)
tree55c504beb2d054b7379a63e28b3eb4fa2888f49b /src/doc/rustc-dev-guide
parentee58570fffaa6a59d13a1b1d6b3ae5ebf07c27fd (diff)
downloadrust-c1658f32a0eeef823559ae29c7ad9dcd6fdbb0bb.tar.gz
rust-c1658f32a0eeef823559ae29c7ad9dcd6fdbb0bb.zip
update examples for rustc 1.69.0-nightly (e1eaa2d5d 2023-02-06) (#1590)
Closes https://github.com/rust-lang/rustc-dev-guide/issues/1581
Diffstat (limited to 'src/doc/rustc-dev-guide')
-rw-r--r--src/doc/rustc-dev-guide/examples/rustc-driver-example.rs8
-rw-r--r--src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs4
-rw-r--r--src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs9
-rw-r--r--src/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md4
-rw-r--r--src/doc/rustc-dev-guide/src/rustc-driver-interacting-with-the-ast.md8
5 files changed, 16 insertions, 17 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 8d8b40cd7ea..13a3ebcc99e 100644
--- a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs
+++ b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs
@@ -12,6 +12,7 @@ extern crate rustc_hir;
 extern crate rustc_interface;
 extern crate rustc_session;
 extern crate rustc_span;
+extern crate rustc_driver;
 
 use std::{path, process, str};
 
@@ -46,7 +47,6 @@ fn main() {
 "#
             .into(),
         },
-        input_path: None,  // Option<PathBuf>
         output_dir: None,  // Option<PathBuf>
         output_file: None, // Option<PathBuf>
         file_loader: None, // Option<Box<dyn FileLoader + Send + Sync>>
@@ -71,17 +71,17 @@ fn main() {
     rustc_interface::run_compiler(config, |compiler| {
         compiler.enter(|queries| {
             // Parse the program and print the syntax tree.
-            let parse = queries.parse().unwrap().take();
+            let parse = queries.parse().unwrap().get_mut().clone();
             println!("{parse:?}");
             // Analyze the program and inspect the types of definitions.
-            queries.global_ctxt().unwrap().take().enter(|tcx| {
+            queries.global_ctxt().unwrap().enter(|tcx| {
                 for id in tcx.hir().items() {
                     let hir = tcx.hir();
                     let item = hir.item(id);
                     match item.kind {
                         rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => {
                             let name = item.ident;
-                            let ty = tcx.type_of(hir.local_def_id(item.hir_id()));
+                            let ty = tcx.type_of(item.hir_id().owner.def_id);
                             println!("{name:?}:\t{ty:?}")
                         }
                         _ => (),
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 49ee9ff44ce..6907252f21f 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
@@ -12,6 +12,7 @@ extern crate rustc_hir;
 extern crate rustc_interface;
 extern crate rustc_session;
 extern crate rustc_span;
+extern crate rustc_driver;
 
 use rustc_errors::registry;
 use rustc_session::config::{self, CheckCfg};
@@ -67,7 +68,6 @@ fn main() {
         },
         crate_cfg: rustc_hash::FxHashSet::default(),
         crate_check_cfg: CheckCfg::default(),
-        input_path: None,
         output_dir: None,
         output_file: None,
         file_loader: None,
@@ -80,7 +80,7 @@ fn main() {
     };
     rustc_interface::run_compiler(config, |compiler| {
         compiler.enter(|queries| {
-            queries.global_ctxt().unwrap().take().enter(|tcx| {
+            queries.global_ctxt().unwrap().enter(|tcx| {
                 // Run the analysis phase on the local crate to trigger the type error.
                 let _ = tcx.analysis(());
             });
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 07b09e9df76..7f9b99e49b0 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
@@ -13,6 +13,7 @@ extern crate rustc_hir;
 extern crate rustc_interface;
 extern crate rustc_session;
 extern crate rustc_span;
+extern crate rustc_driver;
 
 use std::{path, process, str};
 
@@ -45,7 +46,6 @@ fn main() {
         },
         crate_cfg: rustc_hash::FxHashSet::default(),
         crate_check_cfg: CheckCfg::default(),
-        input_path: None,
         output_dir: None,
         output_file: None,
         file_loader: None,
@@ -59,13 +59,12 @@ fn main() {
     rustc_interface::run_compiler(config, |compiler| {
         compiler.enter(|queries| {
             // TODO: add this to -Z unpretty
-            let ast_krate = queries.parse().unwrap().take();
+            let ast_krate = queries.parse().unwrap().get_mut().clone();
             for item in ast_krate.items {
                 println!("{}", item_to_string(&item));
             }
-
             // Analyze the crate and inspect the types under the cursor.
-            queries.global_ctxt().unwrap().take().enter(|tcx| {
+            queries.global_ctxt().unwrap().enter(|tcx| {
                 // 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.
@@ -78,7 +77,7 @@ fn main() {
                             if let rustc_hir::StmtKind::Local(local) = block.stmts[0].kind {
                                 if let Some(expr) = local.init {
                                     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 def_id = item.hir_id().owner.def_id; // def_id identifies the main function
                                     let ty = tcx.typeck(def_id).node_type(hir_id);
                                     println!("{expr:#?}: {ty:?}");
                                 }
diff --git a/src/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md b/src/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md
index bb19ad9d306..cdcd1f58779 100644
--- a/src/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md
+++ b/src/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md
@@ -7,7 +7,7 @@
 To get diagnostics from the compiler,
 configure `rustc_interface::Config` to output diagnostic to a buffer,
 and run `TyCtxt.analysis`. The following was tested
-with <!-- date-check: Jan 2023 --> `nightly-2022-12-19` (See [here][example]
+with <!-- date-check: Feb 2023 --> `nightly-2023-02-06` (See [here][example]
 for the complete example):
 
 [example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-driver-getting-diagnostics.rs
@@ -29,7 +29,7 @@ let config = rustc_interface::Config {
 };
 rustc_interface::run_compiler(config, |compiler| {
     compiler.enter(|queries| {
-        queries.global_ctxt().unwrap().take().enter(|tcx| {
+        queries.global_ctxt().unwrap().enter(|tcx| {
             // Run the analysis phase on the local crate to trigger the type error.
             let _ = tcx.analysis(());
         });
diff --git a/src/doc/rustc-dev-guide/src/rustc-driver-interacting-with-the-ast.md b/src/doc/rustc-dev-guide/src/rustc-driver-interacting-with-the-ast.md
index 5b495b4fe08..b6f3937e8bc 100644
--- a/src/doc/rustc-dev-guide/src/rustc-driver-interacting-with-the-ast.md
+++ b/src/doc/rustc-dev-guide/src/rustc-driver-interacting-with-the-ast.md
@@ -5,7 +5,7 @@
 ## Getting the type of an expression
 
 To get the type of an expression, use the `global_ctxt` to get a `TyCtxt`.
-The following was tested with <!-- date-check: Jan 2023 --> `nightly-2022-12-19`
+The following was tested with <!-- date-check: Feb 2023 --> `nightly-2023-02-06`
 (see [here][example] for the complete example):
 
 [example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-driver-interacting-with-the-ast.rs
@@ -22,7 +22,7 @@ let config = rustc_interface::Config {
 rustc_interface::run_compiler(config, |compiler| {
     compiler.enter(|queries| {
         // Analyze the crate and inspect the types under the cursor.
-        queries.global_ctxt().unwrap().take().enter(|tcx| {
+        queries.global_ctxt().unwrap().enter(|tcx| {
             // 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.
@@ -35,9 +35,9 @@ rustc_interface::run_compiler(config, |compiler| {
                         if let rustc_hir::StmtKind::Local(local) = block.stmts[0].kind {
                             if let Some(expr) = local.init {
                                 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 def_id = item.hir_id().owner.def_id; // def_id identifies the main function
                                 let ty = tcx.typeck(def_id).node_type(hir_id);
-                                println!("{:?}: {:?}", expr, ty);
+                                println!("{expr:#?}: {ty:?}");
                             }
                         }
                     }