about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/structured_errors.rs
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2022-09-26 13:00:29 +0200
committerlcnr <rust@lcnr.de>2022-09-27 10:37:23 +0200
commit1fc86a63f451b81606e4787692517dc613f333db (patch)
tree2b4319f9f442c29fb6be16d4fd98fd27637e8f13 /compiler/rustc_hir_analysis/src/structured_errors.rs
parentde0b511daa91469dd251e736fb8914d2360ac0ec (diff)
downloadrust-1fc86a63f451b81606e4787692517dc613f333db.tar.gz
rust-1fc86a63f451b81606e4787692517dc613f333db.zip
rustc_typeck to rustc_hir_analysis
Diffstat (limited to 'compiler/rustc_hir_analysis/src/structured_errors.rs')
-rw-r--r--compiler/rustc_hir_analysis/src/structured_errors.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/structured_errors.rs b/compiler/rustc_hir_analysis/src/structured_errors.rs
new file mode 100644
index 00000000000..0b46fce1735
--- /dev/null
+++ b/compiler/rustc_hir_analysis/src/structured_errors.rs
@@ -0,0 +1,42 @@
+mod missing_cast_for_variadic_arg;
+mod sized_unsized_cast;
+mod wrong_number_of_generic_args;
+
+pub use self::{
+    missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*,
+};
+
+use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
+use rustc_session::Session;
+
+pub trait StructuredDiagnostic<'tcx> {
+    fn session(&self) -> &Session;
+
+    fn code(&self) -> DiagnosticId;
+
+    fn diagnostic(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
+        let err = self.diagnostic_common();
+
+        if self.session().teach(&self.code()) {
+            self.diagnostic_extended(err)
+        } else {
+            self.diagnostic_regular(err)
+        }
+    }
+
+    fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
+
+    fn diagnostic_regular(
+        &self,
+        err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
+    ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
+        err
+    }
+
+    fn diagnostic_extended(
+        &self,
+        err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
+    ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
+        err
+    }
+}