@@ -56,12 +56,16 @@ bitflags! {
56
56
#[ derive( Debug , Clone , PartialEq , Eq ) ]
57
57
pub struct EnumData {
58
58
pub name : Name ,
59
- pub variants : Box < [ ( EnumVariantId , Name ) ] > ,
60
59
pub repr : Option < ReprOptions > ,
61
60
pub visibility : RawVisibility ,
62
61
pub rustc_has_incoherent_inherent_impls : bool ,
63
62
}
64
63
64
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
65
+ pub struct EnumVariants {
66
+ pub variants : Box < [ ( EnumVariantId , Name ) ] > ,
67
+ }
68
+
65
69
#[ derive( Debug , Clone , PartialEq , Eq ) ]
66
70
pub struct EnumVariantData {
67
71
pub name : Name ,
@@ -203,28 +207,16 @@ impl StructData {
203
207
}
204
208
}
205
209
206
- impl EnumData {
207
- pub ( crate ) fn enum_data_query ( db : & dyn DefDatabase , e : EnumId ) -> Arc < EnumData > {
210
+ impl EnumVariants {
211
+ pub ( crate ) fn enum_variants_query ( db : & dyn DefDatabase , e : EnumId ) -> Arc < EnumVariants > {
208
212
let loc = e. lookup ( db) ;
209
- let krate = loc. container . krate ;
210
213
let item_tree = loc. id . item_tree ( db) ;
211
- let repr = repr_from_value ( db, krate, & item_tree, ModItem :: from ( loc. id . value ) . into ( ) ) ;
212
- let rustc_has_incoherent_inherent_impls = item_tree
213
- . attrs ( db, loc. container . krate , ModItem :: from ( loc. id . value ) . into ( ) )
214
- . by_key ( & sym:: rustc_has_incoherent_inherent_impls)
215
- . exists ( ) ;
216
-
217
- let enum_ = & item_tree[ loc. id . value ] ;
218
214
219
- Arc :: new ( EnumData {
220
- name : enum_. name . clone ( ) ,
215
+ Arc :: new ( EnumVariants {
221
216
variants : loc. container . def_map ( db) . enum_definitions [ & e]
222
217
. iter ( )
223
218
. map ( |& id| ( id, item_tree[ id. lookup ( db) . id . value ] . name . clone ( ) ) )
224
219
. collect ( ) ,
225
- repr,
226
- visibility : item_tree[ enum_. visibility ] . clone ( ) ,
227
- rustc_has_incoherent_inherent_impls,
228
220
} )
229
221
}
230
222
@@ -233,13 +225,6 @@ impl EnumData {
233
225
Some ( id)
234
226
}
235
227
236
- pub fn variant_body_type ( & self ) -> IntegerType {
237
- match self . repr {
238
- Some ( ReprOptions { int : Some ( builtin) , .. } ) => builtin,
239
- _ => IntegerType :: Pointer ( true ) ,
240
- }
241
- }
242
-
243
228
// [Adopted from rustc](https://github.com/rust-lang/rust/blob/bd53aa3bf7a24a70d763182303bd75e5fc51a9af/compiler/rustc_middle/src/ty/adt.rs#L446-L448)
244
229
pub fn is_payload_free ( & self , db : & dyn DefDatabase ) -> bool {
245
230
self . variants . iter ( ) . all ( |( v, _) | {
@@ -262,6 +247,35 @@ impl EnumData {
262
247
}
263
248
}
264
249
250
+ impl EnumData {
251
+ pub ( crate ) fn enum_data_query ( db : & dyn DefDatabase , e : EnumId ) -> Arc < EnumData > {
252
+ let loc = e. lookup ( db) ;
253
+ let krate = loc. container . krate ;
254
+ let item_tree = loc. id . item_tree ( db) ;
255
+ let repr = repr_from_value ( db, krate, & item_tree, ModItem :: from ( loc. id . value ) . into ( ) ) ;
256
+ let rustc_has_incoherent_inherent_impls = item_tree
257
+ . attrs ( db, loc. container . krate , ModItem :: from ( loc. id . value ) . into ( ) )
258
+ . by_key ( & sym:: rustc_has_incoherent_inherent_impls)
259
+ . exists ( ) ;
260
+
261
+ let enum_ = & item_tree[ loc. id . value ] ;
262
+
263
+ Arc :: new ( EnumData {
264
+ name : enum_. name . clone ( ) ,
265
+ repr,
266
+ visibility : item_tree[ enum_. visibility ] . clone ( ) ,
267
+ rustc_has_incoherent_inherent_impls,
268
+ } )
269
+ }
270
+
271
+ pub fn variant_body_type ( & self ) -> IntegerType {
272
+ match self . repr {
273
+ Some ( ReprOptions { int : Some ( builtin) , .. } ) => builtin,
274
+ _ => IntegerType :: Pointer ( true ) ,
275
+ }
276
+ }
277
+ }
278
+
265
279
impl EnumVariantData {
266
280
#[ inline]
267
281
pub ( crate ) fn enum_variant_data_query (
0 commit comments