From a8a8055cc7f8481b0bed653f991648f120ea98a6 Mon Sep 17 00:00:00 2001 From: SLASHLogin Date: Fri, 4 Nov 2022 20:08:01 +0100 Subject: [PATCH] Use `LayoutError`'s implementation of `IntoDiagnostic` --- compiler/rustc_codegen_llvm/src/context.rs | 6 +++--- compiler/rustc_codegen_llvm/src/errors.rs | 8 -------- .../rustc_error_messages/locales/en-US/codegen_llvm.ftl | 3 --- compiler/rustc_middle/src/ty/layout.rs | 8 ++++---- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 7ed4df16ea9..eaa2ccfc835 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -4,7 +4,6 @@ use crate::coverageinfo; use crate::debuginfo; use crate::errors::BranchProtectionRequiresAArch64; -use crate::errors::LayoutSizeOverflow; use crate::llvm; use crate::llvm_util; use crate::type_::Type; @@ -28,6 +27,7 @@ use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet}; use rustc_session::Session; use rustc_span::source_map::Span; +use rustc_span::source_map::Spanned; use rustc_target::abi::{ call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx, }; @@ -953,7 +953,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'_, 'tcx> { #[inline] fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { if let LayoutError::SizeOverflow(_) = err { - self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() }) + self.sess().emit_fatal(Spanned { span, node: err }) } else { span_bug!(span, "failed to get layout for `{}`: {}", ty, err) } @@ -971,7 +971,7 @@ fn handle_fn_abi_err( fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { - self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() }) + self.sess().emit_fatal(Spanned { span, node: err }) } else { match fn_abi_request { FnAbiRequest::OfFnPtr { sig, extra_args } => { diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index 44896a8e8fe..0fafc214f2f 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -55,14 +55,6 @@ pub(crate) struct SymbolAlreadyDefined<'a> { #[diag(codegen_llvm_branch_protection_requires_aarch64)] pub(crate) struct BranchProtectionRequiresAArch64; -#[derive(Diagnostic)] -#[diag(codegen_llvm_layout_size_overflow)] -pub(crate) struct LayoutSizeOverflow { - #[primary_span] - pub span: Span, - pub error: String, -} - #[derive(Diagnostic)] #[diag(codegen_llvm_invalid_minimum_alignment)] pub(crate) struct InvalidMinimumAlignment { diff --git a/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl b/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl index a105b4a64e9..68a205df6c7 100644 --- a/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl +++ b/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl @@ -20,9 +20,6 @@ codegen_llvm_symbol_already_defined = codegen_llvm_branch_protection_requires_aarch64 = -Zbranch-protection is only supported on aarch64 -codegen_llvm_layout_size_overflow = - {$error} - codegen_llvm_invalid_minimum_alignment = invalid minimum global alignment: {$err} diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 3312f44c67b..c74d6bc3774 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -189,8 +189,8 @@ pub enum LayoutError<'tcx> { NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>), } -impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> { - fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> { +impl IntoDiagnostic<'_, !> for LayoutError<'_> { + fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag = handler.struct_fatal(""); match self { @@ -1126,8 +1126,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -impl<'tcx> IntoDiagnostic<'tcx, !> for FnAbiError<'tcx> { - fn into_diagnostic(self, handler: &'tcx Handler) -> DiagnosticBuilder<'tcx, !> { +impl IntoDiagnostic<'_, !> for FnAbiError<'_> { + fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { handler.struct_fatal(self.to_string()) } }