Fix #88256, remove duplicated diagnostic
This commit is contained in:
parent
26feefddc7
commit
ca27f03ca8
11 changed files with 59 additions and 65 deletions
|
@ -9,9 +9,10 @@ use rustc_lint_defs::Applicability;
|
|||
use rustc_serialize::json::Json;
|
||||
use rustc_span::{MultiSpan, Span, DUMMY_SP};
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
|
||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||
pub struct Diagnostic {
|
||||
pub level: Level,
|
||||
pub message: Vec<(String, Style)>,
|
||||
|
@ -24,6 +25,10 @@ pub struct Diagnostic {
|
|||
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
|
||||
/// `span` if there is one. Otherwise, it is `DUMMY_SP`.
|
||||
pub sort_span: Span,
|
||||
|
||||
/// If diagnostic is from Lint, custom hash function ignores notes
|
||||
/// otherwise hash is based on the all the fields
|
||||
pub is_lint: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||
|
@ -91,6 +96,7 @@ impl Diagnostic {
|
|||
children: vec![],
|
||||
suggestions: vec![],
|
||||
sort_span: DUMMY_SP,
|
||||
is_lint: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -558,6 +564,11 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_is_lint(&mut self) -> &mut Self {
|
||||
self.is_lint = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn code(&mut self, s: DiagnosticId) -> &mut Self {
|
||||
self.code = Some(s);
|
||||
self
|
||||
|
@ -617,6 +628,42 @@ impl Diagnostic {
|
|||
let sub = SubDiagnostic { level, message, span, render_span };
|
||||
self.children.push(sub);
|
||||
}
|
||||
|
||||
/// Fields used for Hash, and PartialEq trait
|
||||
fn keys(
|
||||
&self,
|
||||
) -> (
|
||||
&Level,
|
||||
&Vec<(String, Style)>,
|
||||
&Option<DiagnosticId>,
|
||||
&MultiSpan,
|
||||
&Vec<CodeSuggestion>,
|
||||
Option<&Vec<SubDiagnostic>>,
|
||||
) {
|
||||
(
|
||||
&self.level,
|
||||
&self.message,
|
||||
&self.code,
|
||||
&self.span,
|
||||
&self.suggestions,
|
||||
(if self.is_lint { None } else { Some(&self.children) }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Diagnostic {
|
||||
fn hash<H>(&self, state: &mut H)
|
||||
where
|
||||
H: Hasher,
|
||||
{
|
||||
self.keys().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Diagnostic {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.keys() == other.keys()
|
||||
}
|
||||
}
|
||||
|
||||
impl SubDiagnostic {
|
||||
|
|
|
@ -242,6 +242,7 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
sp: S,
|
||||
msg: &str,
|
||||
) -> &mut Self);
|
||||
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
|
||||
|
||||
/// See [`Diagnostic::multipart_suggestion()`].
|
||||
pub fn multipart_suggestion(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue