Skip to content

Commit

Permalink
rust-analyzer: Nest LayoutCalculatorError in hir_ty::LayoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Oct 17, 2024
1 parent 80f5904 commit a5338f7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/tools/rust-analyzer/crates/hir-ty/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ 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
BadCalc(layout::LayoutCalculatorError<()>),
EmptyUnion,
HasErrorConst,
HasErrorType,
Expand All @@ -90,6 +92,7 @@ impl std::error::Error for LayoutError {}
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"),
Expand All @@ -114,11 +117,7 @@ impl fmt::Display for LayoutError {

impl<F> From<LayoutCalculatorError<F>> for LayoutError {
fn from(err: LayoutCalculatorError<F>) -> Self {
match err {
LayoutCalculatorError::EmptyUnion => LayoutError::EmptyUnion,
LayoutCalculatorError::UnexpectedUnsized(_) => LayoutError::UnexpectedUnsized,
LayoutCalculatorError::SizeOverflow => LayoutError::SizeOverflow,
}
LayoutError::BadCalc(err.without_payload())
}
}

Expand Down

0 comments on commit a5338f7

Please sign in to comment.