Rework how diagnostic lints are stored.
`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.
This commit is contained in:
parent
2de99ec787
commit
d71f535a6f
24 changed files with 110 additions and 130 deletions
|
@ -2,7 +2,7 @@ use std::cmp;
|
|||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan};
|
||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||
use rustc_hir::{HirId, ItemLocalId};
|
||||
use rustc_session::lint::{
|
||||
builtin::{self, FORBIDDEN_LINT_GROUPS},
|
||||
|
@ -322,8 +322,6 @@ pub fn struct_lint_level(
|
|||
err.span(span);
|
||||
}
|
||||
|
||||
err.is_lint();
|
||||
|
||||
// If this code originates in a foreign macro, aka something that this crate
|
||||
// did not itself author, then it's likely that there's nothing this crate
|
||||
// can do about it. We probably want to skip the lint entirely.
|
||||
|
@ -351,8 +349,7 @@ pub fn struct_lint_level(
|
|||
// suppressed the lint due to macros.
|
||||
err.primary_message(msg);
|
||||
|
||||
let name = lint.name_lower();
|
||||
err.code(DiagnosticId::Lint { name, has_future_breakage });
|
||||
err.is_lint(lint.name_lower(), has_future_breakage);
|
||||
|
||||
// Lint diagnostics that are covered by the expect level will not be emitted outside
|
||||
// the compiler. It is therefore not necessary to add any information for the user.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue