@@ -56,12 +56,16 @@ bitflags! {
5656#[ derive( Debug , Clone , PartialEq , Eq ) ]
5757pub struct EnumData {
5858 pub name : Name ,
59- pub variants : Box < [ ( EnumVariantId , Name ) ] > ,
6059 pub repr : Option < ReprOptions > ,
6160 pub visibility : RawVisibility ,
6261 pub rustc_has_incoherent_inherent_impls : bool ,
6362}
6463
64+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
65+ pub struct EnumVariants {
66+ pub variants : Box < [ ( EnumVariantId , Name ) ] > ,
67+ }
68+
6569#[ derive( Debug , Clone , PartialEq , Eq ) ]
6670pub struct EnumVariantData {
6771 pub name : Name ,
@@ -203,28 +207,16 @@ impl StructData {
203207 }
204208}
205209
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 > {
208212 let loc = e. lookup ( db) ;
209- let krate = loc. container . krate ;
210213 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 ] ;
218214
219- Arc :: new ( EnumData {
220- name : enum_. name . clone ( ) ,
215+ Arc :: new ( EnumVariants {
221216 variants : loc. container . def_map ( db) . enum_definitions [ & e]
222217 . iter ( )
223218 . map ( |& id| ( id, item_tree[ id. lookup ( db) . id . value ] . name . clone ( ) ) )
224219 . collect ( ) ,
225- repr,
226- visibility : item_tree[ enum_. visibility ] . clone ( ) ,
227- rustc_has_incoherent_inherent_impls,
228220 } )
229221 }
230222
@@ -233,13 +225,6 @@ impl EnumData {
233225 Some ( id)
234226 }
235227
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-
243228 // [Adopted from rustc](https://github.com/rust-lang/rust/blob/bd53aa3bf7a24a70d763182303bd75e5fc51a9af/compiler/rustc_middle/src/ty/adt.rs#L446-L448)
244229 pub fn is_payload_free ( & self , db : & dyn DefDatabase ) -> bool {
245230 self . variants . iter ( ) . all ( |( v, _) | {
@@ -262,6 +247,35 @@ impl EnumData {
262247 }
263248}
264249
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+
265279impl EnumVariantData {
266280 #[ inline]
267281 pub ( crate ) fn enum_variant_data_query (
0 commit comments