Skip to content

Commit d6350f6

Browse files
authored
Rollup merge of #131942 - workingjubilee:reduce-haruspicy, r=lukas-code,lnicola
compiler: Adopt rust-analyzer impls for `LayoutCalculatorError` We're about to massively churn the internals of `rustc_abi`. To minimize the immediate and future impact on rust-analyzer, as a subtree that depends on this crate, grow some API on `LayoutCalculatorError` that reflects their uses of it. This way we can nest the type in theirs, and they can just call functions on it without having to inspect and flatten-out its innards.
2 parents 405740c + 90ec805 commit d6350f6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

crates/hir-ty/src/layout.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx
7272

7373
#[derive(Debug, PartialEq, Eq, Clone)]
7474
pub enum LayoutError {
75+
// FIXME: Remove variants that duplicate LayoutCalculatorError's variants after sync
76+
BadCalc(LayoutCalculatorError<()>),
7577
EmptyUnion,
7678
HasErrorConst,
7779
HasErrorType,
@@ -90,6 +92,7 @@ impl std::error::Error for LayoutError {}
9092
impl fmt::Display for LayoutError {
9193
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9294
match self {
95+
LayoutError::BadCalc(err) => err.fallback_fmt(f),
9396
LayoutError::EmptyUnion => write!(f, "type is an union with no fields"),
9497
LayoutError::HasErrorConst => write!(f, "type contains an unevaluatable const"),
9598
LayoutError::HasErrorType => write!(f, "type contains an error"),
@@ -114,11 +117,7 @@ impl fmt::Display for LayoutError {
114117

115118
impl<F> From<LayoutCalculatorError<F>> for LayoutError {
116119
fn from(err: LayoutCalculatorError<F>) -> Self {
117-
match err {
118-
LayoutCalculatorError::EmptyUnion => LayoutError::EmptyUnion,
119-
LayoutCalculatorError::UnexpectedUnsized(_) => LayoutError::UnexpectedUnsized,
120-
LayoutCalculatorError::SizeOverflow => LayoutError::SizeOverflow,
121-
}
120+
LayoutError::BadCalc(err.without_payload())
122121
}
123122
}
124123

0 commit comments

Comments
 (0)