mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 12:07:40 +00:00

`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
37 lines
951 B
Rust
37 lines
951 B
Rust
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};
|
|
use rustc_session::Session;
|
|
|
|
pub trait StructuredDiagnostic<'tcx> {
|
|
fn session(&self) -> &Session;
|
|
|
|
fn code(&self) -> DiagnosticId;
|
|
|
|
fn diagnostic(&self) -> DiagnosticBuilder<'tcx> {
|
|
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>;
|
|
|
|
fn diagnostic_regular(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
|
err
|
|
}
|
|
|
|
fn diagnostic_extended(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
|
err
|
|
}
|
|
}
|