Skip to content

Commit 329eef0

Browse files
committed
Add more LayoutError variants
1 parent 62aac8d commit 329eef0

File tree

1 file changed

+8
-3
lines changed
  • src/tools/rust-analyzer/crates/hir-ty/src

1 file changed

+8
-3
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/layout.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx
7272

7373
#[derive(Debug, PartialEq, Eq, Clone)]
7474
pub enum LayoutError {
75+
EmptyUnion,
7576
HasErrorConst,
7677
HasErrorType,
7778
HasPlaceholder,
@@ -80,6 +81,7 @@ pub enum LayoutError {
8081
RecursiveTypeWithoutIndirection,
8182
SizeOverflow,
8283
TargetLayoutNotAvailable,
84+
UnexpectedUnsized,
8385
Unknown,
8486
UserReprTooSmall,
8587
}
@@ -88,6 +90,7 @@ impl std::error::Error for LayoutError {}
8890
impl fmt::Display for LayoutError {
8991
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9092
match self {
93+
LayoutError::EmptyUnion => write!(f, "type is an union with no fields"),
9194
LayoutError::HasErrorConst => write!(f, "type contains an unevaluatable const"),
9295
LayoutError::HasErrorType => write!(f, "type contains an error"),
9396
LayoutError::HasPlaceholder => write!(f, "type contains placeholders"),
@@ -98,6 +101,9 @@ impl fmt::Display for LayoutError {
98101
}
99102
LayoutError::SizeOverflow => write!(f, "size overflow"),
100103
LayoutError::TargetLayoutNotAvailable => write!(f, "target layout not available"),
104+
LayoutError::UnexpectedUnsized => {
105+
write!(f, "an unsized type was found where a sized type was expected")
106+
}
101107
LayoutError::Unknown => write!(f, "unknown"),
102108
LayoutError::UserReprTooSmall => {
103109
write!(f, "the `#[repr]` hint is too small to hold the discriminants of the enum")
@@ -109,9 +115,8 @@ impl fmt::Display for LayoutError {
109115
impl<F> From<LayoutCalculatorError<F>> for LayoutError {
110116
fn from(err: LayoutCalculatorError<F>) -> Self {
111117
match err {
112-
LayoutCalculatorError::UnexpectedUnsized(_) | LayoutCalculatorError::EmptyUnion => {
113-
LayoutError::Unknown
114-
}
118+
LayoutCalculatorError::EmptyUnion => LayoutError::EmptyUnion,
119+
LayoutCalculatorError::UnexpectedUnsized(_) => LayoutError::UnexpectedUnsized,
115120
LayoutCalculatorError::SizeOverflow => LayoutError::SizeOverflow,
116121
}
117122
}

0 commit comments

Comments
 (0)