about summary refs log tree commit diff
path: root/compiler/rustc_passes/src/liveness.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-26 02:24:39 +0000
committerbors <bors@rust-lang.org>2023-12-26 02:24:39 +0000
commit2271c26e4a8e062bb00d709d0ccb5846e0c341b9 (patch)
treea3457e0d9b89710e476158cdaffbddb2b7876c6b /compiler/rustc_passes/src/liveness.rs
parente4c626dd9a17a23270bf8e7158e59cf2b9c04840 (diff)
parent8a9db2545919f945ffbb215e4325917e0bfc5b3a (diff)
downloadrust-2271c26e4a8e062bb00d709d0ccb5846e0c341b9.tar.gz
rust-2271c26e4a8e062bb00d709d0ccb5846e0c341b9.zip
Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors
Remove `DiagCtxt` API duplication

`DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods.

Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`.

This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates.

This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.)

After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`.

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_passes/src/liveness.rs')
-rw-r--r--compiler/rustc_passes/src/liveness.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs
index c9e5eb50b3a..a8ba9838780 100644
--- a/compiler/rustc_passes/src/liveness.rs
+++ b/compiler/rustc_passes/src/liveness.rs
@@ -592,7 +592,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
         match self.successors[ln] {
             Some(successor) => self.assigned_on_entry(successor, var),
             None => {
-                self.ir.tcx.sess.span_delayed_bug(DUMMY_SP, "no successor");
+                self.ir.tcx.dcx().span_delayed_bug(DUMMY_SP, "no successor");
                 true
             }
         }