]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_typeck/src/structured_errors.rs
Sync rust-lang/portable-simd@5f49d4c8435a25d804b2f375e949cb25479f5be9
[rust.git] / compiler / rustc_typeck / src / structured_errors.rs
1 mod missing_cast_for_variadic_arg;
2 mod sized_unsized_cast;
3 mod wrong_number_of_generic_args;
4
5 pub use self::{
6     missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*,
7 };
8
9 use rustc_errors::{DiagnosticBuilder, DiagnosticId};
10 use rustc_session::Session;
11
12 pub trait StructuredDiagnostic<'tcx> {
13     fn session(&self) -> &Session;
14
15     fn code(&self) -> DiagnosticId;
16
17     fn diagnostic(&self) -> DiagnosticBuilder<'tcx> {
18         let err = self.diagnostic_common();
19
20         if self.session().teach(&self.code()) {
21             self.diagnostic_extended(err)
22         } else {
23             self.diagnostic_regular(err)
24         }
25     }
26
27     fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx>;
28
29     fn diagnostic_regular(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
30         err
31     }
32
33     fn diagnostic_extended(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
34         err
35     }
36 }