diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-10 19:12:40 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-10 19:12:40 +0000 |
commit | dc2a8d5acc53054c86ad17260b69d4bf4f14dbc6 (patch) | |
tree | ddf2dbe793448d3e913f869c7dab91ce7175b623 /crates/ra_hir/src/code_model_api.rs | |
parent | a95536301c346e68a109915e6d54136cae875ab0 (diff) | |
parent | e78286c8e88d31045d354320a1d29bbd75405027 (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.rs | 34 |
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 | ||
190 | impl Enum { | 191 | impl 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)] |
210 | pub struct EnumVariant { | ||
211 | pub(crate) def_id: DefId, | ||
212 | } | ||
213 | |||
214 | impl 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)] | ||
205 | pub struct Function { | 237 | pub struct Function { |
206 | pub(crate) def_id: DefId, | 238 | pub(crate) def_id: DefId, |
207 | } | 239 | } |