Commit 2271c26
committed
Auto merge of rust-lang#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`File tree
347 files changed
+2334
-2696
lines changed- compiler
- rustc_ast_lowering/src
- rustc_ast_passes/src
- rustc_attr/src
- rustc_borrowck/src
- diagnostics
- region_infer
- type_check
- rustc_builtin_macros/src
- deriving
- cmp
- generic
- rustc_codegen_cranelift/src
- abi
- driver
- intrinsics
- rustc_codegen_gcc/src
- intrinsic
- rustc_codegen_llvm/src
- back
- rustc_codegen_ssa/src
- back
- debuginfo
- mir
- rustc_const_eval/src
- const_eval
- interpret
- transform
- check_consts
- rustc_driver_impl/src
- rustc_errors/src
- rustc_expand/src
- mbe
- rustc_hir_analysis/src
- astconv
- check
- compare_impl_item
- coherence
- collect
- type_of
- impl_wf_check
- outlives
- structured_errors
- variance
- rustc_hir_typeck/src
- fn_ctxt
- method
- rustc_incremental/src
- persist
- rustc_infer/src
- infer
- canonical
- error_reporting
- nice_region_error
- lexical_region_resolve
- opaque_types
- outlives
- relate
- traits/error_reporting
- rustc_interface/src
- rustc_lint/src
- rustc_metadata/src
- rmeta
- rustc_middle/src
- middle
- mir/interpret
- query
- traits
- ty
- util
- rustc_mir_build/src
- build
- custom
- expr
- thir
- cx
- pattern
- rustc_mir_dataflow/src
- framework
- rustc_mir_transform/src
- rustc_monomorphize/src
- rustc_parse/src
- lexer
- parser
- rustc_passes/src
- rustc_pattern_analysis/src
- rustc_privacy/src
- rustc_query_impl/src
- rustc_query_system/src
- dep_graph
- query
- rustc_resolve/src
- late
- rustc_session/src
- rustc_symbol_mangling/src
- typeid
- rustc_trait_selection/src
- solve/normalizes_to
- traits
- error_reporting
- query
- type_op
- select
- specialize
- rustc_ty_utils/src
- src
- librustdoc
- clean
- html
- render
- passes
- tools
- clippy
- clippy_config/src
- clippy_lints/src
- clippy_utils/src
- miri/src
- bin
- borrow_tracker
- tests/run-make-fulldeps
- hotplug_codegen_backend
- obtain-borrowck
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
347 files changed
+2334
-2696
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
142 | | - | |
| 146 | + | |
143 | 147 | | |
144 | 148 | | |
145 | 149 | | |
| |||
276 | 280 | | |
277 | 281 | | |
278 | 282 | | |
279 | | - | |
| 283 | + | |
280 | 284 | | |
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
284 | 288 | | |
285 | 289 | | |
286 | 290 | | |
287 | | - | |
| 291 | + | |
288 | 292 | | |
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
292 | 296 | | |
293 | 297 | | |
294 | | - | |
| 298 | + | |
295 | 299 | | |
296 | 300 | | |
297 | 301 | | |
| |||
315 | 319 | | |
316 | 320 | | |
317 | 321 | | |
318 | | - | |
| 322 | + | |
319 | 323 | | |
320 | 324 | | |
321 | 325 | | |
| |||
384 | 388 | | |
385 | 389 | | |
386 | 390 | | |
387 | | - | |
| 391 | + | |
388 | 392 | | |
389 | 393 | | |
390 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
298 | | - | |
| 297 | + | |
299 | 298 | | |
300 | 299 | | |
301 | 300 | | |
| |||
332 | 331 | | |
333 | 332 | | |
334 | 333 | | |
335 | | - | |
336 | | - | |
337 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
338 | 337 | | |
339 | 338 | | |
340 | 339 | | |
| |||
584 | 583 | | |
585 | 584 | | |
586 | 585 | | |
587 | | - | |
| 586 | + | |
588 | 587 | | |
589 | 588 | | |
590 | | - | |
| 589 | + | |
591 | 590 | | |
592 | 591 | | |
593 | | - | |
| 592 | + | |
594 | 593 | | |
595 | 594 | | |
596 | 595 | | |
| |||
902 | 901 | | |
903 | 902 | | |
904 | 903 | | |
905 | | - | |
| 904 | + | |
906 | 905 | | |
907 | 906 | | |
908 | 907 | | |
| |||
1129 | 1128 | | |
1130 | 1129 | | |
1131 | 1130 | | |
1132 | | - | |
| 1131 | + | |
1133 | 1132 | | |
1134 | 1133 | | |
1135 | 1134 | | |
| |||
1142 | 1141 | | |
1143 | 1142 | | |
1144 | 1143 | | |
1145 | | - | |
| 1144 | + | |
1146 | 1145 | | |
1147 | 1146 | | |
1148 | 1147 | | |
| |||
1181 | 1180 | | |
1182 | 1181 | | |
1183 | 1182 | | |
1184 | | - | |
| 1183 | + | |
1185 | 1184 | | |
1186 | 1185 | | |
1187 | 1186 | | |
| |||
1192 | 1191 | | |
1193 | 1192 | | |
1194 | 1193 | | |
1195 | | - | |
| 1194 | + | |
1196 | 1195 | | |
1197 | 1196 | | |
1198 | 1197 | | |
| |||
1448 | 1447 | | |
1449 | 1448 | | |
1450 | 1449 | | |
1451 | | - | |
| 1450 | + | |
1452 | 1451 | | |
1453 | 1452 | | |
1454 | 1453 | | |
| |||
1544 | 1543 | | |
1545 | 1544 | | |
1546 | 1545 | | |
1547 | | - | |
| 1546 | + | |
1548 | 1547 | | |
1549 | 1548 | | |
1550 | 1549 | | |
| |||
1653 | 1652 | | |
1654 | 1653 | | |
1655 | 1654 | | |
1656 | | - | |
| 1655 | + | |
1657 | 1656 | | |
1658 | 1657 | | |
1659 | 1658 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
879 | 879 | | |
880 | 880 | | |
881 | 881 | | |
882 | | - | |
| 882 | + | |
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
| |||
1012 | 1012 | | |
1013 | 1013 | | |
1014 | 1014 | | |
1015 | | - | |
| 1015 | + | |
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
| |||
1022 | 1022 | | |
1023 | 1023 | | |
1024 | 1024 | | |
1025 | | - | |
| 1025 | + | |
1026 | 1026 | | |
1027 | 1027 | | |
1028 | 1028 | | |
| |||
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
1299 | | - | |
| 1299 | + | |
1300 | 1300 | | |
1301 | 1301 | | |
1302 | 1302 | | |
| |||
1383 | 1383 | | |
1384 | 1384 | | |
1385 | 1385 | | |
1386 | | - | |
| 1386 | + | |
1387 | 1387 | | |
1388 | 1388 | | |
1389 | 1389 | | |
| |||
0 commit comments