From 1fc86a63f451b81606e4787692517dc613f333db Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 26 Sep 2022 13:00:29 +0200 Subject: rustc_typeck to rustc_hir_analysis --- .../rustc_hir_analysis/src/structured_errors.rs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 compiler/rustc_hir_analysis/src/structured_errors.rs (limited to 'compiler/rustc_hir_analysis/src/structured_errors.rs') 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 + } +} -- cgit 1.4.1-3-g733a5