Skip to content

Commit 9a2d1fd

Browse files
committed
Following commit 401dd84 in the Rust project
(https://github.com/rust-lang/rust), `ErrorGuaranteed` was replaced by fatal errors. As a result, `tcx.analysis()` now aborts directly instead of returning an error guard. To accommodate this change, this update replaces `tcx.analysis()` with `typeck()` to perform type checking in the example.
1 parent a4b76e3 commit 9a2d1fd

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tested with nightly-2025-02-13
1+
// Tested with nightly-2025-03-08
22

33
#![feature(rustc_private)]
44

@@ -86,8 +86,10 @@ fn main() {
8686
rustc_interface::run_compiler(config, |compiler| {
8787
let krate = rustc_interface::passes::parse(&compiler.sess);
8888
rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
89-
// Run the analysis phase on the local crate to trigger the type error.
90-
let _ = tcx.analysis(());
89+
// Iterate all the items defined and perform type checking.
90+
tcx.par_hir_body_owners(|item_def_id| {
91+
tcx.ensure_ok().typeck(item_def_id);
92+
});
9193
});
9294
// If the compiler has encountered errors when this closure returns, it will abort (!) the program.
9395
// We avoid this by resetting the error count before returning

src/doc/rustc-dev-guide/src/rustc-driver/getting-diagnostics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ otherwise be printed to stderr.
77

88
To get diagnostics from the compiler,
99
configure [`rustc_interface::Config`] to output diagnostic to a buffer,
10-
and run [`TyCtxt.analysis`].
10+
and run [`rustc_hir_typeck::typeck`] for each item.
1111

1212
```rust
1313
{{#include ../../examples/rustc-interface-getting-diagnostics.rs}}
@@ -16,3 +16,4 @@ and run [`TyCtxt.analysis`].
1616
[`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
1717
[`rustc_interface::Config`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html
1818
[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html
19+
[`rustc_hir_typeck::typeck`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn.typeck.html

0 commit comments

Comments
 (0)