migrate dead.rs to translateable diagnostics
This commit is contained in:
parent
f0afb88302
commit
a7aa1850b2
4 changed files with 20 additions and 17 deletions
|
@ -558,3 +558,9 @@ passes_incorrect_target =
|
||||||
[one] argument
|
[one] argument
|
||||||
*[other] arguments
|
*[other] arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
passes_useless_assignment =
|
||||||
|
useless assignment of {$is_field_assign ->
|
||||||
|
[true] field
|
||||||
|
*[false] variable
|
||||||
|
} of type `{$ty}` to itself
|
||||||
|
|
|
@ -988,11 +988,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
|
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
|
||||||
if self.inner.borrow().has_errors() {
|
if self.inner.borrow().has_errors() { Some(ErrorGuaranteed(())) } else { None }
|
||||||
Some(ErrorGuaranteed(()))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
|
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
|
||||||
if self.inner.borrow().has_errors_or_lint_errors() {
|
if self.inner.borrow().has_errors_or_lint_errors() {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{pluralize, Applicability, DelayDm, MultiSpan};
|
use rustc_errors::{pluralize, Applicability, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
|
@ -18,6 +18,8 @@ use rustc_session::lint;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
use crate::errors::UselessAssignment;
|
||||||
|
|
||||||
// Any local node that may call something in its body block should be
|
// Any local node that may call something in its body block should be
|
||||||
// explored. For example, if it's a live Node::Item that is a
|
// explored. For example, if it's a live Node::Item that is a
|
||||||
// function, then we should explore its block to check for codes that
|
// function, then we should explore its block to check for codes that
|
||||||
|
@ -180,19 +182,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||||
&& !assign.span.from_expansion()
|
&& !assign.span.from_expansion()
|
||||||
{
|
{
|
||||||
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));
|
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));
|
||||||
self.tcx.struct_span_lint_hir(
|
self.tcx.emit_spanned_lint(
|
||||||
lint::builtin::DEAD_CODE,
|
lint::builtin::DEAD_CODE,
|
||||||
assign.hir_id,
|
assign.hir_id,
|
||||||
assign.span,
|
assign.span,
|
||||||
DelayDm(|| format!(
|
UselessAssignment { is_field_assign, ty: self.typeck_results().expr_ty(lhs) }
|
||||||
"useless assignment of {} of type `{}` to itself",
|
|
||||||
if is_field_assign { "field" } else { "variable" },
|
|
||||||
self.typeck_results().expr_ty(lhs),
|
|
||||||
)),
|
|
||||||
|lint| {
|
|
||||||
lint
|
|
||||||
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_ast::Label;
|
||||||
use rustc_errors::{error_code, Applicability, ErrorGuaranteed, IntoDiagnostic, MultiSpan};
|
use rustc_errors::{error_code, Applicability, ErrorGuaranteed, IntoDiagnostic, MultiSpan};
|
||||||
use rustc_hir::{self as hir, ExprKind, Target};
|
use rustc_hir::{self as hir, ExprKind, Target};
|
||||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::MainDefinition;
|
use rustc_middle::ty::{MainDefinition, Ty};
|
||||||
use rustc_span::{Span, Symbol, DUMMY_SP};
|
use rustc_span::{Span, Symbol, DUMMY_SP};
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
|
@ -1265,3 +1265,10 @@ pub struct IncorrectTarget<'a> {
|
||||||
pub actual_num: usize,
|
pub actual_num: usize,
|
||||||
pub at_least: bool,
|
pub at_least: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(passes::useless_assignment)]
|
||||||
|
pub struct UselessAssignment<'a> {
|
||||||
|
pub is_field_assign: bool,
|
||||||
|
pub ty: Ty<'a>,
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue