diff --git a/examples/rustc-driver-example.rs b/examples/rustc-driver-example.rs index 7177a2868..8a5d880fa 100644 --- a/examples/rustc-driver-example.rs +++ b/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/examples/rustc-driver-getting-diagnostics.rs b/examples/rustc-driver-getting-diagnostics.rs index c25695dd0..3bb0d5450 100644 --- a/examples/rustc-driver-getting-diagnostics.rs +++ b/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/examples/rustc-driver-interacting-with-the-ast.rs b/examples/rustc-driver-interacting-with-the-ast.rs index c942ac324..a0110f82d 100644 --- a/examples/rustc-driver-interacting-with-the-ast.rs +++ b/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); } } } diff --git a/src/rustc-driver-getting-diagnostics.md b/src/rustc-driver-getting-diagnostics.md index fa5ce0750..b3f18a67e 100644 --- a/src/rustc-driver-getting-diagnostics.md +++ b/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 should be compiled -with `nightly-2021-03-28` (See [here][example] +with `nightly-2021-04-30` (See [here][example] for the complete example): [example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-driver-getting-diagnostics.rs @@ -35,7 +35,7 @@ rustc_interface::run_compiler(config, |compiler| { compiler.enter(|queries| { queries.global_ctxt().unwrap().take().enter(|tcx| { // Run the analysis phase on the local crate to trigger the type error. - tcx.analysis(rustc_hir::def_id::LOCAL_CRATE); + let _ = tcx.analysis(()); }); }); }); diff --git a/src/rustc-driver-interacting-with-the-ast.md b/src/rustc-driver-interacting-with-the-ast.md index 7cb53187b..1ec9c1c32 100644 --- a/src/rustc-driver-interacting-with-the-ast.md +++ b/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 should be compiled with `nightly-2021-03-28` +The following should be compiled with `nightly-2022-04-30` (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 @@ -24,9 +24,10 @@ rustc_interface::run_compiler(config, |compiler| { // Analyze the crate and inspect the types under the cursor. queries.global_ctxt().unwrap().take().enter(|tcx| { // Every compilation contains a single crate. - let hir_krate = tcx.hir().krate(); + 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; @@ -36,7 +37,7 @@ rustc_interface::run_compiler(config, |compiler| { 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); } } } diff --git a/src/rustc-driver.md b/src/rustc-driver.md index 2cffba42c..7250c852c 100644 --- a/src/rustc-driver.md +++ b/src/rustc-driver.md @@ -7,7 +7,7 @@ using the interface defined in the [`rustc_interface`] crate. The `rustc_interface` crate provides external users with an (unstable) API for running code at particular times during the compilation process, allowing third parties to effectively use `rustc`'s internals as a library for -analysing a crate or emulating the compiler in-process (e.g. the RLS or rustdoc). +analyzing a crate or emulating the compiler in-process (e.g. the RLS or rustdoc). For those using `rustc` as a library, the [`rustc_interface::run_compiler()`][i_rc] function is the main entrypoint to the compiler. It takes a configuration for the compiler