aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-10 19:12:40 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-10 19:12:40 +0000
commitdc2a8d5acc53054c86ad17260b69d4bf4f14dbc6 (patch)
treeddf2dbe793448d3e913f869c7dab91ce7175b623 /crates/ra_hir/src/code_model_api.rs
parenta95536301c346e68a109915e6d54136cae875ab0 (diff)
parente78286c8e88d31045d354320a1d29bbd75405027 (diff)
Merge #470
470: Type inference for enum variants r=flodiebold a=marcusklaas Opened a new PR instead of https://github.com/rust-analyzer/rust-analyzer/pull/461. Totally botched that one. I think I resolved all the issues mentioned there. Co-authored-by: Marcus Klaas de Vries <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs34
1 files changed, 33 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index fa3e4baa7..725bc7d80 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -44,6 +44,7 @@ pub enum Def {
44 Module(Module), 44 Module(Module),
45 Struct(Struct), 45 Struct(Struct),
46 Enum(Enum), 46 Enum(Enum),
47 EnumVariant(EnumVariant),
47 Function(Function), 48 Function(Function),
48 Item, 49 Item,
49} 50}
@@ -188,6 +189,10 @@ pub struct Enum {
188} 189}
189 190
190impl Enum { 191impl Enum {
192 pub(crate) fn new(def_id: DefId) -> Self {
193 Enum { def_id }
194 }
195
191 pub fn def_id(&self) -> DefId { 196 pub fn def_id(&self) -> DefId {
192 self.def_id 197 self.def_id
193 } 198 }
@@ -196,12 +201,39 @@ impl Enum {
196 Ok(db.enum_data(self.def_id)?.name.clone()) 201 Ok(db.enum_data(self.def_id)?.name.clone())
197 } 202 }
198 203
199 pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> { 204 pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, EnumVariant)>> {
200 Ok(db.enum_data(self.def_id)?.variants.clone()) 205 Ok(db.enum_data(self.def_id)?.variants.clone())
201 } 206 }
202} 207}
203 208
204#[derive(Debug, Clone, PartialEq, Eq, Hash)] 209#[derive(Debug, Clone, PartialEq, Eq, Hash)]
210pub struct EnumVariant {
211 pub(crate) def_id: DefId,
212}
213
214impl EnumVariant {
215 pub(crate) fn new(def_id: DefId) -> Self {
216 EnumVariant { def_id }
217 }
218
219 pub fn def_id(&self) -> DefId {
220 self.def_id
221 }
222
223 pub fn parent_enum(&self, db: &impl HirDatabase) -> Cancelable<Enum> {
224 Ok(db.enum_variant_data(self.def_id)?.parent_enum.clone())
225 }
226
227 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
228 Ok(db.enum_variant_data(self.def_id)?.name.clone())
229 }
230
231 pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> {
232 Ok(db.enum_variant_data(self.def_id)?.variant_data.clone())
233 }
234}
235
236#[derive(Debug, Clone, PartialEq, Eq, Hash)]
205pub struct Function { 237pub struct Function {
206 pub(crate) def_id: DefId, 238 pub(crate) def_id: DefId,
207} 239}