Use `LayoutError`'s implementation of `IntoDiagnostic`

This commit is contained in:
SLASHLogin 2022-11-04 20:08:01 +01:00
parent 0381e51822
commit a8a8055cc7
4 changed files with 7 additions and 18 deletions

View File

@ -4,7 +4,6 @@ use crate::callee::get_fn;
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::{BranchProtection, CFGuard, CFProtection};
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 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
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 } => {

View File

@ -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 {

View File

@ -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}

View File

@ -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 @@ impl<'tcx> fmt::Display for FnAbiError<'tcx> {
}
}
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())
}
}