Skip to content

Commit 610b875

Browse files
authored
Update the rustc_interface examples for current rustc (#1974)
1 parent 4b692c0 commit 610b875

5 files changed

+14
-14
lines changed

examples/rustc-driver-example.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
4848
lint_caps: FxHashMap::default(), // FxHashMap<lint::LintId, lint::Level>
4949
// This is a callback from the driver that is called when [`ParseSess`] is created.
50-
parse_sess_created: None, //Option<Box<dyn FnOnce(&mut ParseSess) + Send>>
50+
psess_created: None, //Option<Box<dyn FnOnce(&mut ParseSess) + Send>>
5151
// This is a callback from the driver that is called when we're registering lints;
5252
// it is called during plugin registration when we have the LintStore in a non-shared state.
5353
//
@@ -60,7 +60,7 @@ fn main() {
6060
// The second parameter is local providers and the third parameter is external providers.
6161
override_queries: None, // Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>
6262
// Registry of diagnostics codes.
63-
registry: registry::Registry::new(rustc_error_codes::DIAGNOSTICS),
63+
registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS),
6464
make_codegen_backend: None,
6565
expanded_args: Vec::new(),
6666
ice_file: None,

examples/rustc-driver-getting-diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl Translate for DebugEmitter {
3636
}
3737

3838
impl Emitter for DebugEmitter {
39-
fn emit_diagnostic(&mut self, diag: &DiagInner) {
40-
self.diagnostics.lock().unwrap().push(diag.clone());
39+
fn emit_diagnostic(&mut self, diag: DiagInner) {
40+
self.diagnostics.lock().unwrap().push(diag);
4141
}
4242

4343
fn source_map(&self) -> Option<&Arc<SourceMap>> {
@@ -76,15 +76,15 @@ fn main() {
7676
file_loader: None,
7777
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
7878
lint_caps: rustc_hash::FxHashMap::default(),
79-
parse_sess_created: Some(Box::new(|parse_sess| {
80-
parse_sess.dcx = DiagCtxt::with_emitter(Box::new(DebugEmitter {
79+
psess_created: Some(Box::new(|parse_sess| {
80+
parse_sess.dcx = DiagCtxt::new(Box::new(DebugEmitter {
8181
source_map: parse_sess.clone_source_map(),
8282
diagnostics,
8383
}))
8484
})),
8585
register_lints: None,
8686
override_queries: None,
87-
registry: registry::Registry::new(rustc_error_codes::DIAGNOSTICS),
87+
registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS),
8888
make_codegen_backend: None,
8989
expanded_args: Vec::new(),
9090
ice_file: None,

examples/rustc-driver-interacting-with-the-ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ fn main() {
4545
file_loader: None,
4646
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
4747
lint_caps: rustc_hash::FxHashMap::default(),
48-
parse_sess_created: None,
48+
psess_created: None,
4949
register_lints: None,
5050
override_queries: None,
5151
make_codegen_backend: None,
52-
registry: registry::Registry::new(rustc_error_codes::DIAGNOSTICS),
52+
registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS),
5353
expanded_args: Vec::new(),
5454
ice_file: None,
5555
hash_untracked_state: None,
@@ -73,8 +73,8 @@ fn main() {
7373
if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind {
7474
let expr = &tcx.hir().body(body_id).value;
7575
if let rustc_hir::ExprKind::Block(block, _) = expr.kind {
76-
if let rustc_hir::StmtKind::Local(local) = block.stmts[0].kind {
77-
if let Some(expr) = local.init {
76+
if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind {
77+
if let Some(expr) = let_stmt.init {
7878
let hir_id = expr.hir_id; // hir_id identifies the string "Hello, world!"
7979
let def_id = item.hir_id().owner.def_id; // def_id identifies the main function
8080
let ty = tcx.typeck(def_id).node_type(hir_id);

src/rustc-driver-getting-diagnostics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ otherwise be printed to stderr.
88
To get diagnostics from the compiler,
99
configure [`rustc_interface::Config`] to output diagnostic to a buffer,
1010
and run [`TyCtxt.analysis`]. The following was tested
11-
with <!-- date-check: jan 2024 --> `nightly-2024-01-19`:
11+
with <!-- date-check: may 2024 --> `nightly-2024-05-09`:
1212

1313
```rust
1414
{{#include ../examples/rustc-driver-getting-diagnostics.rs}}
1515
```
1616

1717
[`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
1818
[`rustc_interface::Config`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html
19-
[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html
19+
[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html

src/rustc-driver-interacting-with-the-ast.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The [`rustc_interface`] allows you to interact with Rust code at various stages
55
## Getting the type of an expression
66

77
To get the type of an expression, use the [`global_ctxt`] query to [get] a [`TyCtxt`].
8-
The following was tested with <!-- date-check: jan 2024 --> `nightly-2024-01-19`:
8+
The following was tested with <!-- date-check: may 2024 --> `nightly-2024-05-09`:
99

1010
```rust
1111
{{#include ../examples/rustc-driver-interacting-with-the-ast.rs}}

0 commit comments

Comments
 (0)