@@ -73,7 +73,7 @@ use once_cell::unsync::Lazy;
7373use rustc_hash:: FxHashSet ;
7474use stdx:: { impl_from, never} ;
7575use syntax:: {
76- ast:: { self , HasAttrs as _, HasDocComments , HasName } ,
76+ ast:: { self , Expr , HasAttrs as _, HasDocComments , HasName } ,
7777 AstNode , AstPtr , SmolStr , SyntaxNodePtr , TextRange , T ,
7878} ;
7979
@@ -962,11 +962,16 @@ impl HasVisibility for Enum {
962962
963963#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
964964pub struct Variant {
965- pub ( crate ) parent : Enum ,
966- pub ( crate ) id : LocalEnumVariantId ,
965+ pub parent : Enum ,
966+ pub id : LocalEnumVariantId ,
967967}
968968
969969impl Variant {
970+ pub fn value ( self , db : & dyn HirDatabase ) -> Option < Expr > {
971+ // TODO(ole): Handle missing exprs (+1 to the prev)
972+ self . source ( db) ?. value . expr ( )
973+ }
974+
970975 pub fn module ( self , db : & dyn HirDatabase ) -> Module {
971976 self . parent . module ( db)
972977 }
@@ -1129,6 +1134,7 @@ pub enum DefWithBody {
11291134 Function ( Function ) ,
11301135 Static ( Static ) ,
11311136 Const ( Const ) ,
1137+ Variant ( Variant ) ,
11321138}
11331139impl_from ! ( Function , Const , Static for DefWithBody ) ;
11341140
@@ -1138,6 +1144,7 @@ impl DefWithBody {
11381144 DefWithBody :: Const ( c) => c. module ( db) ,
11391145 DefWithBody :: Function ( f) => f. module ( db) ,
11401146 DefWithBody :: Static ( s) => s. module ( db) ,
1147+ DefWithBody :: Variant ( v) => v. module ( db) ,
11411148 }
11421149 }
11431150
@@ -1146,6 +1153,7 @@ impl DefWithBody {
11461153 DefWithBody :: Function ( f) => Some ( f. name ( db) ) ,
11471154 DefWithBody :: Static ( s) => Some ( s. name ( db) ) ,
11481155 DefWithBody :: Const ( c) => c. name ( db) ,
1156+ DefWithBody :: Variant ( v) => Some ( v. name ( db) ) ,
11491157 }
11501158 }
11511159
@@ -1155,6 +1163,7 @@ impl DefWithBody {
11551163 DefWithBody :: Function ( it) => it. ret_type ( db) ,
11561164 DefWithBody :: Static ( it) => it. ty ( db) ,
11571165 DefWithBody :: Const ( it) => it. ty ( db) ,
1166+ DefWithBody :: Variant ( it) => it. parent . ty ( db) ,
11581167 }
11591168 }
11601169
@@ -1379,6 +1388,7 @@ impl DefWithBody {
13791388 DefWithBody :: Function ( it) => it. into ( ) ,
13801389 DefWithBody :: Static ( it) => it. into ( ) ,
13811390 DefWithBody :: Const ( it) => it. into ( ) ,
1391+ DefWithBody :: Variant ( it) => it. into ( ) ,
13821392 } ;
13831393 for diag in hir_ty:: diagnostics:: incorrect_case ( db, krate, def. into ( ) ) {
13841394 acc. push ( diag. into ( ) )
0 commit comments