@@ -72,16 +72,15 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx
72
72
73
73
#[ derive( Debug , PartialEq , Eq , Clone ) ]
74
74
pub enum LayoutError {
75
- EmptyUnion ,
75
+ // FIXME: Remove more variants once they get added to LayoutCalculatorError
76
+ BadCalc ( LayoutCalculatorError < ( ) > ) ,
76
77
HasErrorConst ,
77
78
HasErrorType ,
78
79
HasPlaceholder ,
79
80
InvalidSimdType ,
80
81
NotImplemented ,
81
82
RecursiveTypeWithoutIndirection ,
82
- SizeOverflow ,
83
83
TargetLayoutNotAvailable ,
84
- UnexpectedUnsized ,
85
84
Unknown ,
86
85
UserReprTooSmall ,
87
86
}
@@ -90,7 +89,7 @@ impl std::error::Error for LayoutError {}
90
89
impl fmt:: Display for LayoutError {
91
90
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
92
91
match self {
93
- LayoutError :: EmptyUnion => write ! ( f , "type is an union with no fields" ) ,
92
+ LayoutError :: BadCalc ( err ) => err . fallback_fmt ( f ) ,
94
93
LayoutError :: HasErrorConst => write ! ( f, "type contains an unevaluatable const" ) ,
95
94
LayoutError :: HasErrorType => write ! ( f, "type contains an error" ) ,
96
95
LayoutError :: HasPlaceholder => write ! ( f, "type contains placeholders" ) ,
@@ -99,11 +98,7 @@ impl fmt::Display for LayoutError {
99
98
LayoutError :: RecursiveTypeWithoutIndirection => {
100
99
write ! ( f, "recursive type without indirection" )
101
100
}
102
- LayoutError :: SizeOverflow => write ! ( f, "size overflow" ) ,
103
101
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
- }
107
102
LayoutError :: Unknown => write ! ( f, "unknown" ) ,
108
103
LayoutError :: UserReprTooSmall => {
109
104
write ! ( f, "the `#[repr]` hint is too small to hold the discriminants of the enum" )
@@ -114,11 +109,7 @@ impl fmt::Display for LayoutError {
114
109
115
110
impl < F > From < LayoutCalculatorError < F > > for LayoutError {
116
111
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 ( ) )
122
113
}
123
114
}
124
115
@@ -182,7 +173,10 @@ fn layout_of_simd_ty(
182
173
} ;
183
174
184
175
// 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 ) ) ?;
186
180
let align = dl. vector_align ( size) ;
187
181
let size = size. align_to ( align. abi ) ;
188
182
@@ -295,7 +289,10 @@ pub fn layout_of_ty_query(
295
289
TyKind :: Array ( element, count) => {
296
290
let count = try_const_usize ( db, count) . ok_or ( LayoutError :: HasErrorConst ) ? as u64 ;
297
291
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 ) ) ?;
299
296
300
297
let abi = if count != 0 && matches ! ( element. abi, Abi :: Uninhabited ) {
301
298
Abi :: Uninhabited
0 commit comments