mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00

`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not.
37 lines
929 B
Rust
37 lines
929 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;
|
|
use rustc_session::Session;
|
|
|
|
pub trait StructuredDiagnostic<'tcx> {
|
|
fn session(&self) -> &Session;
|
|
|
|
fn code(&self) -> String;
|
|
|
|
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
|
|
}
|
|
}
|