rust/compiler/rustc_codegen_llvm/src
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
..
back Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
coverageinfo coverage: Avoid creating func_coverage for marker statements 2023-12-16 11:10:11 +11:00
debuginfo Unify SourceFile::name_hash and StableSourceFileId 2023-12-19 22:34:26 +01:00
llvm fix: stop emitting .debug_pubnames and .debug_pubtypes 2023-12-11 14:58:02 -05:00
abi.rs remove redundant imports 2023-12-10 10:56:22 +08:00
allocator.rs Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkin 2023-12-14 11:14:03 +00:00
asm.rs Auto merge of #114467 - Amanieu:asm-unstable-features, r=davidtwco 2023-08-15 11:59:02 +00:00
attributes.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
base.rs compiler: replace cstr macro with c str literals in compiler and few other c str replacements 2023-12-03 14:54:09 +03:00
builder.rs NFC: do not clone types that are copy 2023-12-15 23:19:51 +01:00
callee.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
common.rs ctfe interpreter: extend provenance so that it can track whether a pointer is immutable 2023-12-07 17:46:36 +01:00
consts.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
context.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
declare.rs Add unstable -Zdefault-hidden-visibility cmdline flag for rustc. 2023-12-13 21:14:23 +00:00
errors.rs Improve some names. 2023-12-23 13:23:28 +11:00
intrinsic.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
lib.rs update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
llvm_util.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
mono_item.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
type_.rs remove unused pub fn 2023-11-23 14:11:02 +03:00
type_of.rs Clean dead codes 2023-11-26 09:25:07 +08:00
va_arg.rs cg_llvm: remove pointee types and pointercast/bitcast-of-ptr 2023-07-29 13:18:17 -04:00
value.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00