Replace some LayoutError variants with the rustc_abi errors

This commit is contained in:
Laurențiu Nicola 2024-10-22 10:19:25 +03:00
parent 8d479d099b
commit a32039278f
2 changed files with 22 additions and 24 deletions

26
Cargo.lock generated
View file

@ -1497,9 +1497,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_abi"
version = "0.71.0"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6999d098000b98415939f13158dac78cb3eeeb7b0c073847f3e4b623866e27c"
checksum = "879ece0781e3c1cb670b9f29775c81a43a16db789d1296fad6bc5c74065b2fac"
dependencies = [
"bitflags 2.6.0",
"ra-ap-rustc_index",
@ -1508,9 +1508,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_index"
version = "0.71.0"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae9fb312d942817dab10790881f555928c1f6a11a85186e8e573ad4a86c7d3be"
checksum = "6910087ff89bb9f3db114bfcd86b5139042731fe7278d3ff4ceaa69a140154a7"
dependencies = [
"arrayvec",
"ra-ap-rustc_index_macros",
@ -1519,9 +1519,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.71.0"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "766e3990eb1066a06deefc561b5a01b32ca5c9211feea31cbf4ed50611519872"
checksum = "3b6f7bd12b678fbb37444ba77f3b0cfc13b7394a6dc7b0c799491fc9df0a9997"
dependencies = [
"proc-macro2",
"quote",
@ -1530,9 +1530,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_lexer"
version = "0.71.0"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4afa98eb7889c137d5a3f1cd189089e16da04d1e4837d358a67aa3dab10ffbe"
checksum = "119bc05b5b6bc3e7f5b67ce8b8080e185da94bd83c447f91b6b3f3ecf60cbab1"
dependencies = [
"unicode-properties",
"unicode-xid",
@ -1540,9 +1540,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.71.0"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9234c96ffb0565286790407fb7eb7f55ebf69267de4db382fdec0a17f14b0e2"
checksum = "70ed6150ae71d905c064dc88d7824ebb0fa81083f45d7477cba7b57176f2f635"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
@ -1550,12 +1550,12 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.71.0"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "273d5f72926a58c7eea27aebc898d1d5b32d23d2342f692a94a2cf8746aa4a2f"
checksum = "6e830862a0ec85fce211d34735315686bb8d6a12d418d6d735fb534aa1cd3293"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 1.1.0",
"rustc-hash 2.0.0",
"rustc_apfloat",
"smallvec",
"tracing",

View file

@ -72,18 +72,15 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum LayoutError {
// FIXME: Remove variants that duplicate LayoutCalculatorError's variants after sync
// FIXME: Remove more variants once they get added to LayoutCalculatorError
BadCalc(LayoutCalculatorError<()>),
EmptyUnion,
HasErrorConst,
HasErrorType,
HasPlaceholder,
InvalidSimdType,
NotImplemented,
RecursiveTypeWithoutIndirection,
SizeOverflow,
TargetLayoutNotAvailable,
UnexpectedUnsized,
Unknown,
UserReprTooSmall,
}
@ -93,7 +90,6 @@ impl fmt::Display for LayoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LayoutError::BadCalc(err) => err.fallback_fmt(f),
LayoutError::EmptyUnion => write!(f, "type is an union with no fields"),
LayoutError::HasErrorConst => write!(f, "type contains an unevaluatable const"),
LayoutError::HasErrorType => write!(f, "type contains an error"),
LayoutError::HasPlaceholder => write!(f, "type contains placeholders"),
@ -102,11 +98,7 @@ impl fmt::Display for LayoutError {
LayoutError::RecursiveTypeWithoutIndirection => {
write!(f, "recursive type without indirection")
}
LayoutError::SizeOverflow => write!(f, "size overflow"),
LayoutError::TargetLayoutNotAvailable => write!(f, "target layout not available"),
LayoutError::UnexpectedUnsized => {
write!(f, "an unsized type was found where a sized type was expected")
}
LayoutError::Unknown => write!(f, "unknown"),
LayoutError::UserReprTooSmall => {
write!(f, "the `#[repr]` hint is too small to hold the discriminants of the enum")
@ -181,7 +173,10 @@ fn layout_of_simd_ty(
};
// Compute the size and alignment of the vector:
let size = e_ly.size.checked_mul(e_len, dl).ok_or(LayoutError::SizeOverflow)?;
let size = e_ly
.size
.checked_mul(e_len, dl)
.ok_or(LayoutError::BadCalc(LayoutCalculatorError::SizeOverflow))?;
let align = dl.vector_align(size);
let size = size.align_to(align.abi);
@ -294,7 +289,10 @@ pub fn layout_of_ty_query(
TyKind::Array(element, count) => {
let count = try_const_usize(db, count).ok_or(LayoutError::HasErrorConst)? as u64;
let element = db.layout_of_ty(element.clone(), trait_env)?;
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
let size = element
.size
.checked_mul(count, dl)
.ok_or(LayoutError::BadCalc(LayoutCalculatorError::SizeOverflow))?;
let abi = if count != 0 && matches!(element.abi, Abi::Uninhabited) {
Abi::Uninhabited