Rollup merge of #103397 - crlf0710:port_dead_code_lint, r=davidtwco

Port `dead_code` lints to be translatable.

This adds an additional comma to lists with three or more items, to be consistent with list formatters like `icu4x`.

r? `@davidtwco`
This commit is contained in:
Matthias Krüger 2022-11-04 18:52:26 +01:00 committed by GitHub
commit 612bb7890c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 215 additions and 99 deletions

View file

@ -4,7 +4,9 @@ use std::{
};
use rustc_ast::Label;
use rustc_errors::{error_code, Applicability, ErrorGuaranteed, IntoDiagnostic, MultiSpan};
use rustc_errors::{
error_code, Applicability, DiagnosticSymbolList, ErrorGuaranteed, IntoDiagnostic, MultiSpan,
};
use rustc_hir::{self as hir, ExprKind, Target};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{MainDefinition, Ty};
@ -1446,3 +1448,59 @@ pub struct MissingConstErr {
#[label]
pub const_span: Span,
}
#[derive(LintDiagnostic)]
pub enum MultipleDeadCodes<'tcx> {
#[diag(passes_dead_codes)]
DeadCodes {
multiple: bool,
num: usize,
descr: &'tcx str,
participle: &'tcx str,
name_list: DiagnosticSymbolList,
#[subdiagnostic]
parent_info: Option<ParentInfo<'tcx>>,
#[subdiagnostic]
ignored_derived_impls: Option<IgnoredDerivedImpls>,
},
#[diag(passes_dead_codes)]
UnusedTupleStructFields {
multiple: bool,
num: usize,
descr: &'tcx str,
participle: &'tcx str,
name_list: DiagnosticSymbolList,
#[subdiagnostic]
change_fields_suggestion: ChangeFieldsToBeOfUnitType,
#[subdiagnostic]
parent_info: Option<ParentInfo<'tcx>>,
#[subdiagnostic]
ignored_derived_impls: Option<IgnoredDerivedImpls>,
},
}
#[derive(Subdiagnostic)]
#[label(passes_parent_info)]
pub struct ParentInfo<'tcx> {
pub num: usize,
pub descr: &'tcx str,
pub parent_descr: &'tcx str,
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic)]
#[note(passes_ignored_derived_impls)]
pub struct IgnoredDerivedImpls {
pub name: Symbol,
pub trait_list: DiagnosticSymbolList,
pub trait_list_len: usize,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
pub struct ChangeFieldsToBeOfUnitType {
pub num: usize,
#[suggestion_part(code = "()")]
pub spans: Vec<Span>,
}