Use translatable diagnostics in rustc_const_eval
This commit is contained in:
parent
642c92e630
commit
4f83717cf7
93 changed files with 2375 additions and 1123 deletions
|
@ -1,7 +1,9 @@
|
|||
use crate::base;
|
||||
use crate::common::{self, CodegenCx};
|
||||
use crate::debuginfo;
|
||||
use crate::errors::{InvalidMinimumAlignment, SymbolAlreadyDefined};
|
||||
use crate::errors::{
|
||||
InvalidMinimumAlignmentNotPowerOfTwo, InvalidMinimumAlignmentTooLarge, SymbolAlreadyDefined,
|
||||
};
|
||||
use crate::llvm::{self, True};
|
||||
use crate::type_::Type;
|
||||
use crate::type_of::LayoutLlvmExt;
|
||||
|
@ -19,7 +21,9 @@ use rustc_middle::ty::layout::LayoutOf;
|
|||
use rustc_middle::ty::{self, Instance, Ty};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::config::Lto;
|
||||
use rustc_target::abi::{Align, HasDataLayout, Primitive, Scalar, Size, WrappingRange};
|
||||
use rustc_target::abi::{
|
||||
Align, AlignFromBytesError, HasDataLayout, Primitive, Scalar, Size, WrappingRange,
|
||||
};
|
||||
use std::ops::Range;
|
||||
|
||||
pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value {
|
||||
|
@ -129,9 +133,14 @@ fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align:
|
|||
if let Some(min) = cx.sess().target.min_global_align {
|
||||
match Align::from_bits(min) {
|
||||
Ok(min) => align = align.max(min),
|
||||
Err(err) => {
|
||||
cx.sess().emit_err(InvalidMinimumAlignment { err });
|
||||
}
|
||||
Err(err) => match err {
|
||||
AlignFromBytesError::NotPowerOfTwo(align) => {
|
||||
cx.sess().emit_err(InvalidMinimumAlignmentNotPowerOfTwo { align });
|
||||
}
|
||||
AlignFromBytesError::TooLarge(align) => {
|
||||
cx.sess().emit_err(InvalidMinimumAlignmentTooLarge { align });
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
|
|
|
@ -969,9 +969,9 @@ 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(Spanned { span, node: err })
|
||||
self.sess().emit_fatal(Spanned { span, node: err.into_diagnostic() })
|
||||
} else {
|
||||
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
|
||||
span_bug!(span, "failed to get layout for `{ty}`: {err:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -991,21 +991,12 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
|
|||
} else {
|
||||
match fn_abi_request {
|
||||
FnAbiRequest::OfFnPtr { sig, extra_args } => {
|
||||
span_bug!(
|
||||
span,
|
||||
"`fn_abi_of_fn_ptr({}, {:?})` failed: {}",
|
||||
sig,
|
||||
extra_args,
|
||||
err
|
||||
);
|
||||
span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}",);
|
||||
}
|
||||
FnAbiRequest::OfInstance { instance, extra_args } => {
|
||||
span_bug!(
|
||||
span,
|
||||
"`fn_abi_of_instance({}, {:?})` failed: {}",
|
||||
instance,
|
||||
extra_args,
|
||||
err
|
||||
"`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,15 @@ pub(crate) struct SymbolAlreadyDefined<'a> {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_invalid_minimum_alignment)]
|
||||
pub(crate) struct InvalidMinimumAlignment {
|
||||
pub err: String,
|
||||
#[diag(codegen_llvm_invalid_minimum_alignment_not_power_of_two)]
|
||||
pub(crate) struct InvalidMinimumAlignmentNotPowerOfTwo {
|
||||
pub align: u64,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_invalid_minimum_alignment_too_large)]
|
||||
pub(crate) struct InvalidMinimumAlignmentTooLarge {
|
||||
pub align: u64,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue