From 5d6cff69d0733ba5c70d0fe945d97fc0289bd0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Fri, 17 May 2024 12:46:15 +0200 Subject: [PATCH] Derive both Diagnostic and LintDiagnostic on some tys --- .../src/coherence/orphan.rs | 4 +-- compiler/rustc_hir_analysis/src/errors.rs | 31 ++----------------- compiler/rustc_passes/src/check_attr.rs | 5 ++- compiler/rustc_passes/src/errors.rs | 9 +----- 4 files changed, 7 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index e31a12e10d39..cbc191afd74e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -514,12 +514,12 @@ fn lint_uncovered_ty_params<'tcx>( Some(local_type) => tcx.emit_node_lint( UNCOVERED_PARAM_IN_PROJECTION, hir_id, - errors::TyParamFirstLocalLint { span, note: (), param: name, local_type }, + errors::TyParamFirstLocal { span, note: (), param: name, local_type }, ), None => tcx.emit_node_lint( UNCOVERED_PARAM_IN_PROJECTION, hir_id, - errors::TyParamSomeLint { span, note: (), param: name }, + errors::TyParamSome { span, note: (), param: name }, ), }; } diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 6423c6ae4ec9..636e35c4bbcf 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1358,9 +1358,7 @@ pub struct CrossCrateTraitsDefined { pub traits: String, } -// FIXME(fmease): Deduplicate: - -#[derive(Diagnostic)] +#[derive(Diagnostic, LintDiagnostic)] #[diag(hir_analysis_ty_param_first_local, code = E0210)] #[note] pub struct TyParamFirstLocal<'tcx> { @@ -1373,20 +1371,7 @@ pub struct TyParamFirstLocal<'tcx> { pub local_type: Ty<'tcx>, } -#[derive(LintDiagnostic)] -#[diag(hir_analysis_ty_param_first_local, code = E0210)] -#[note] -pub struct TyParamFirstLocalLint<'tcx> { - #[primary_span] - #[label] - pub span: Span, - #[note(hir_analysis_case_note)] - pub note: (), - pub param: Symbol, - pub local_type: Ty<'tcx>, -} - -#[derive(Diagnostic)] +#[derive(Diagnostic, LintDiagnostic)] #[diag(hir_analysis_ty_param_some, code = E0210)] #[note] pub struct TyParamSome { @@ -1398,18 +1383,6 @@ pub struct TyParamSome { pub param: Symbol, } -#[derive(LintDiagnostic)] -#[diag(hir_analysis_ty_param_some, code = E0210)] -#[note] -pub struct TyParamSomeLint { - #[primary_span] - #[label] - pub span: Span, - #[note(hir_analysis_only_note)] - pub note: (), - pub param: Symbol, -} - #[derive(Diagnostic)] pub enum OnlyCurrentTraits { #[diag(hir_analysis_only_current_traits_outside, code = E0117)] diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 6fb50d059577..08012fbe4e85 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1907,8 +1907,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { }); } if is_explicit_rust && (int_reprs > 0 || is_c || is_simd) { - let hint_spans = hint_spans.clone().collect(); - self.dcx().emit_err(errors::ReprConflicting { hint_spans }); + self.dcx().emit_err(errors::ReprConflicting { spans: hint_spans.clone().collect() }); } // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8) if (int_reprs > 1) @@ -1925,7 +1924,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.tcx.emit_node_lint( CONFLICTING_REPR_HINTS, hir_id, - errors::ReprConflictingLint { spans: hint_spans.collect() }, + errors::ReprConflicting { spans: hint_spans.collect() }, ); } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 19d675087ab5..251f269fdf01 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -609,16 +609,9 @@ pub struct ReprIdent { pub span: Span, } -#[derive(Diagnostic)] +#[derive(Diagnostic, LintDiagnostic)] #[diag(passes_repr_conflicting, code = E0566)] pub struct ReprConflicting { - #[primary_span] - pub hint_spans: Vec, -} - -#[derive(LintDiagnostic)] -#[diag(passes_repr_conflicting, code = E0566)] -pub struct ReprConflictingLint { #[primary_span] pub spans: Vec, }