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
|
@ -16,7 +16,7 @@ use rustc_ast::ptr::P;
|
|||
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
|
||||
use rustc_ast::*;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||
use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticId, IntoDiagnosticArg};
|
||||
use rustc_errors::{Applicability, DiagnosticArgValue, IntoDiagnosticArg};
|
||||
use rustc_hir::def::Namespace::{self, *};
|
||||
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
|
@ -531,7 +531,7 @@ impl<'a> PathSource<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn error_code(self, has_unexpected_resolution: bool) -> DiagnosticId {
|
||||
fn error_code(self, has_unexpected_resolution: bool) -> String {
|
||||
use rustc_errors::error_code;
|
||||
match (self, has_unexpected_resolution) {
|
||||
(PathSource::Trait(_), true) => error_code!(E0404),
|
||||
|
@ -3759,7 +3759,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
swap(&mut err.span, &mut parent_err.span);
|
||||
err.children = take(&mut parent_err.children);
|
||||
err.sort_span = parent_err.sort_span;
|
||||
err.is_lint = parent_err.is_lint;
|
||||
err.is_lint = parent_err.is_lint.clone();
|
||||
|
||||
// merge the parent's suggestions with the typo suggestions
|
||||
fn append_result<T, E>(res1: &mut Result<Vec<T>, E>, res2: Result<Vec<T>, E>) {
|
||||
|
|
|
@ -257,7 +257,7 @@ enum ResolutionError<'a> {
|
|||
kind: &'static str,
|
||||
trait_path: String,
|
||||
trait_item_span: Span,
|
||||
code: rustc_errors::DiagnosticId,
|
||||
code: String,
|
||||
},
|
||||
/// Error E0201: multiple impl items for the same trait item.
|
||||
TraitImplDuplicate { name: Symbol, trait_item_span: Span, old_span: Span },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue