diff options
| author | Matthew Woodcraft <matthew@woodcraft.me.uk> | 2024-05-11 00:06:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-11 00:06:30 +0100 |
| commit | 417afb2145f9137365170cd147d37fff7cd1ffdb (patch) | |
| tree | 9d17ee2469694b78641fe17fb895492131525123 /src/doc/rustc-dev-guide | |
| parent | 95fef283f54ba905329fbd09c5cabe2dba034252 (diff) | |
| download | rust-417afb2145f9137365170cd147d37fff7cd1ffdb.tar.gz rust-417afb2145f9137365170cd147d37fff7cd1ffdb.zip | |
Update the rustc_interface examples for current rustc (#1974)
Diffstat (limited to 'src/doc/rustc-dev-guide')
5 files changed, 14 insertions, 14 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 3e22586d7b2..a86a256d487 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs @@ -47,7 +47,7 @@ fn main() { locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES, lint_caps: FxHashMap::default(), // FxHashMap<lint::LintId, lint::Level> // This is a callback from the driver that is called when [`ParseSess`] is created. - parse_sess_created: None, //Option<Box<dyn FnOnce(&mut ParseSess) + Send>> + psess_created: None, //Option<Box<dyn FnOnce(&mut ParseSess) + Send>> // 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<fn(&Session, &mut ty::query::Providers<'_>, &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/src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs b/src/doc/rustc-dev-guide/examples/rustc-driver-getting-diagnostics.rs index ba63a1ad4b4..f9fe7f5f3ff 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 @@ -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<SourceMap>> { @@ -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/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 104a7a7de70..b6026fd9bec 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 @@ -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/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md b/src/doc/rustc-dev-guide/src/rustc-driver-getting-diagnostics.md index 7cf4f119388..db8be88db90 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 @@ -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 <!-- date-check: jan 2024 --> `nightly-2024-01-19`: +with <!-- date-check: may 2024 --> `nightly-2024-05-09`: ```rust {{#include ../examples/rustc-driver-getting-diagnostics.rs}} @@ -16,4 +16,4 @@ with <!-- date-check: jan 2024 --> `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/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 5de22d8b014..98a19bd79d4 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 @@ 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 <!-- date-check: jan 2024 --> `nightly-2024-01-19`: +The following was tested with <!-- date-check: may 2024 --> `nightly-2024-05-09`: ```rust {{#include ../examples/rustc-driver-interacting-with-the-ast.rs}} |
