rust/compiler
bors 2271c26e4a 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`
2023-12-26 02:24:39 +00:00
..
rustc
rustc_abi
rustc_arena
rustc_ast Rollup merge of #119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=compiler-errors 2023-12-23 16:23:54 +01:00
rustc_ast_lowering Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_ast_passes Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_ast_pretty Rollup merge of #119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=compiler-errors 2023-12-23 16:23:54 +01:00
rustc_attr Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_baked_icu_data
rustc_borrowck Remove MirBorrowckCtxt methods that duplicate DiagCtxt methods. 2023-12-24 08:17:46 +11:00
rustc_builtin_macros Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_codegen_cranelift Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_codegen_gcc Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_codegen_llvm Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_codegen_ssa Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_const_eval Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_data_structures
rustc_driver
rustc_driver_impl Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_error_codes move rustc_outlives test code from query to dedicated function 2023-12-23 13:59:10 +01:00
rustc_error_messages
rustc_errors Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_expand Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_feature Auto merge of #119211 - rust-lang:pa-master-1.77, r=Mark-Simulacrum 2023-12-23 00:26:47 +00:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-errors,dtolnay 2023-12-22 21:41:04 -05:00
rustc_hir_analysis Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_hir_pretty
rustc_hir_typeck Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_incremental Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_index
rustc_index_macros
rustc_infer Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_interface Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_lexer
rustc_lint Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_lint_defs Auto merge of #116274 - RalfJung:soft_unstable, r=cjgillot 2023-12-25 16:26:15 +00:00
rustc_llvm
rustc_log
rustc_macros
rustc_metadata Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_middle Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_mir_build Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_mir_dataflow Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_mir_transform Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_monomorphize Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_next_trait_solver
rustc_parse Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_parse_format
rustc_passes Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_pattern_analysis Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_privacy Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_query_impl Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_query_system Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_resolve Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_serialize
rustc_session Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_smir Split coroutine desugaring kind from source 2023-12-22 23:58:29 +00:00
rustc_span Auto merge of #119139 - michaelwoerister:cleanup-stable-source-file-id, r=cjgillot 2023-12-24 21:58:39 +00:00
rustc_symbol_mangling Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_target Rollup merge of #112936 - Toasterson:illumos-aarch64-target, r=jackh726 2023-12-23 20:02:27 +01:00
rustc_trait_selection Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_traits
rustc_transmute
rustc_ty_utils Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_type_ir
stable_mir Split coroutine desugaring kind from source 2023-12-22 23:58:29 +00:00