From 46025dd5499469fdbeeee0ae93360af4492f5ec1 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Thu, 9 May 2024 22:20:41 +0100 Subject: [PATCH] Update the rustc_interface examples for current rustc --- examples/rustc-driver-example.rs | 4 ++-- examples/rustc-driver-getting-diagnostics.rs | 10 +++++----- examples/rustc-driver-interacting-with-the-ast.rs | 8 ++++---- src/rustc-driver-getting-diagnostics.md | 4 ++-- src/rustc-driver-interacting-with-the-ast.md | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/rustc-driver-example.rs b/examples/rustc-driver-example.rs index 3e22586d7..a86a256d4 100644 --- a/examples/rustc-driver-example.rs +++ b/examples/rustc-driver-example.rs @@ -47,7 +47,7 @@ fn main() { locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES, lint_caps: FxHashMap::default(), // FxHashMap // This is a callback from the driver that is called when [`ParseSess`] is created. - parse_sess_created: None, //Option> + psess_created: None, //Option> // This is a callback from the driver that is called when we're registering lints; // it is called during plugin registration when we have the LintStore in a non-shared state. // @@ -60,7 +60,7 @@ fn main() { // The second parameter is local providers and the third parameter is external providers. override_queries: None, // Option, &mut ty::query::Providers<'_>)> // Registry of diagnostics codes. - registry: registry::Registry::new(rustc_error_codes::DIAGNOSTICS), + registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS), make_codegen_backend: None, expanded_args: Vec::new(), ice_file: None, diff --git a/examples/rustc-driver-getting-diagnostics.rs b/examples/rustc-driver-getting-diagnostics.rs index ba63a1ad4..f9fe7f5f3 100644 --- a/examples/rustc-driver-getting-diagnostics.rs +++ b/examples/rustc-driver-getting-diagnostics.rs @@ -36,8 +36,8 @@ impl Translate for DebugEmitter { } impl Emitter for DebugEmitter { - fn emit_diagnostic(&mut self, diag: &DiagInner) { - self.diagnostics.lock().unwrap().push(diag.clone()); + fn emit_diagnostic(&mut self, diag: DiagInner) { + self.diagnostics.lock().unwrap().push(diag); } fn source_map(&self) -> Option<&Arc> { @@ -76,15 +76,15 @@ fn main() { file_loader: None, locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES, lint_caps: rustc_hash::FxHashMap::default(), - parse_sess_created: Some(Box::new(|parse_sess| { - parse_sess.dcx = DiagCtxt::with_emitter(Box::new(DebugEmitter { + psess_created: Some(Box::new(|parse_sess| { + parse_sess.dcx = DiagCtxt::new(Box::new(DebugEmitter { source_map: parse_sess.clone_source_map(), diagnostics, })) })), register_lints: None, override_queries: None, - registry: registry::Registry::new(rustc_error_codes::DIAGNOSTICS), + registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS), make_codegen_backend: None, expanded_args: Vec::new(), ice_file: None, diff --git a/examples/rustc-driver-interacting-with-the-ast.rs b/examples/rustc-driver-interacting-with-the-ast.rs index 104a7a7de..b6026fd9b 100644 --- a/examples/rustc-driver-interacting-with-the-ast.rs +++ b/examples/rustc-driver-interacting-with-the-ast.rs @@ -45,11 +45,11 @@ fn main() { file_loader: None, locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES, lint_caps: rustc_hash::FxHashMap::default(), - parse_sess_created: None, + psess_created: None, register_lints: None, override_queries: None, make_codegen_backend: None, - registry: registry::Registry::new(rustc_error_codes::DIAGNOSTICS), + registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS), expanded_args: Vec::new(), ice_file: None, hash_untracked_state: None, @@ -73,8 +73,8 @@ fn main() { if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind { let expr = &tcx.hir().body(body_id).value; if let rustc_hir::ExprKind::Block(block, _) = expr.kind { - if let rustc_hir::StmtKind::Local(local) = block.stmts[0].kind { - if let Some(expr) = local.init { + if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind { + if let Some(expr) = let_stmt.init { let hir_id = expr.hir_id; // hir_id identifies the string "Hello, world!" 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); diff --git a/src/rustc-driver-getting-diagnostics.md b/src/rustc-driver-getting-diagnostics.md index 7cf4f1193..db8be88db 100644 --- a/src/rustc-driver-getting-diagnostics.md +++ b/src/rustc-driver-getting-diagnostics.md @@ -8,7 +8,7 @@ otherwise be printed to stderr. 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 `nightly-2024-01-19`: +with `nightly-2024-05-09`: ```rust {{#include ../examples/rustc-driver-getting-diagnostics.rs}} @@ -16,4 +16,4 @@ with `nightly-2024-01-19`: [`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html [`rustc_interface::Config`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html -[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html \ No newline at end of file +[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html diff --git a/src/rustc-driver-interacting-with-the-ast.md b/src/rustc-driver-interacting-with-the-ast.md index 5de22d8b0..98a19bd79 100644 --- a/src/rustc-driver-interacting-with-the-ast.md +++ b/src/rustc-driver-interacting-with-the-ast.md @@ -5,7 +5,7 @@ The [`rustc_interface`] allows you to interact with Rust code at various stages ## Getting the type of an expression To get the type of an expression, use the [`global_ctxt`] query to [get] a [`TyCtxt`]. -The following was tested with `nightly-2024-01-19`: +The following was tested with `nightly-2024-05-09`: ```rust {{#include ../examples/rustc-driver-interacting-with-the-ast.rs}}