@@ -72,16 +72,15 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx
7272
7373#[ derive( Debug , PartialEq , Eq , Clone ) ]
7474pub enum LayoutError {
75- EmptyUnion ,
75+ // FIXME: Remove more variants once they get added to LayoutCalculatorError
76+ BadCalc ( LayoutCalculatorError < ( ) > ) ,
7677 HasErrorConst ,
7778 HasErrorType ,
7879 HasPlaceholder ,
7980 InvalidSimdType ,
8081 NotImplemented ,
8182 RecursiveTypeWithoutIndirection ,
82- SizeOverflow ,
8383 TargetLayoutNotAvailable ,
84- UnexpectedUnsized ,
8584 Unknown ,
8685 UserReprTooSmall ,
8786}
@@ -90,7 +89,7 @@ impl std::error::Error for LayoutError {}
9089impl fmt:: Display for LayoutError {
9190 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
9291 match self {
93- LayoutError :: EmptyUnion => write ! ( f , "type is an union with no fields" ) ,
92+ LayoutError :: BadCalc ( err ) => err . fallback_fmt ( f ) ,
9493 LayoutError :: HasErrorConst => write ! ( f, "type contains an unevaluatable const" ) ,
9594 LayoutError :: HasErrorType => write ! ( f, "type contains an error" ) ,
9695 LayoutError :: HasPlaceholder => write ! ( f, "type contains placeholders" ) ,
@@ -99,11 +98,7 @@ impl fmt::Display for LayoutError {
9998 LayoutError :: RecursiveTypeWithoutIndirection => {
10099 write ! ( f, "recursive type without indirection" )
101100 }
102- LayoutError :: SizeOverflow => write ! ( f, "size overflow" ) ,
103101 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- }
107102 LayoutError :: Unknown => write ! ( f, "unknown" ) ,
108103 LayoutError :: UserReprTooSmall => {
109104 write ! ( f, "the `#[repr]` hint is too small to hold the discriminants of the enum" )
@@ -114,11 +109,7 @@ impl fmt::Display for LayoutError {
114109
115110impl < F > From < LayoutCalculatorError < F > > for LayoutError {
116111 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- }
112+ LayoutError :: BadCalc ( err. without_payload ( ) )
122113 }
123114}
124115
@@ -182,7 +173,10 @@ fn layout_of_simd_ty(
182173 } ;
183174
184175 // Compute the size and alignment of the vector:
185- let size = e_ly. size . checked_mul ( e_len, dl) . ok_or ( LayoutError :: SizeOverflow ) ?;
176+ let size = e_ly
177+ . size
178+ . checked_mul ( e_len, dl)
179+ . ok_or ( LayoutError :: BadCalc ( LayoutCalculatorError :: SizeOverflow ) ) ?;
186180 let align = dl. vector_align ( size) ;
187181 let size = size. align_to ( align. abi ) ;
188182
@@ -295,7 +289,10 @@ pub fn layout_of_ty_query(
295289 TyKind :: Array ( element, count) => {
296290 let count = try_const_usize ( db, count) . ok_or ( LayoutError :: HasErrorConst ) ? as u64 ;
297291 let element = db. layout_of_ty ( element. clone ( ) , trait_env) ?;
298- let size = element. size . checked_mul ( count, dl) . ok_or ( LayoutError :: SizeOverflow ) ?;
292+ let size = element
293+ . size
294+ . checked_mul ( count, dl)
295+ . ok_or ( LayoutError :: BadCalc ( LayoutCalculatorError :: SizeOverflow ) ) ?;
299296
300297 let abi = if count != 0 && matches ! ( element. abi, Abi :: Uninhabited ) {
301298 Abi :: Uninhabited
0 commit comments