diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 7b8dbe6b7..3674688ef 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -16,7 +16,7 @@ use ra_syntax::{ | |||
16 | }; | 16 | }; |
17 | 17 | ||
18 | use crate::{ | 18 | use crate::{ |
19 | Def, DefId, FnScopes, Module, Function, Struct, Path, | 19 | Def, DefId, FnScopes, Module, Function, Struct, Enum, Path, |
20 | db::HirDatabase, | 20 | db::HirDatabase, |
21 | adt::VariantData, | 21 | adt::VariantData, |
22 | }; | 22 | }; |
@@ -251,7 +251,18 @@ pub fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { | |||
251 | pub fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> { | 251 | pub fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> { |
252 | Ok(Ty::Adt { | 252 | Ok(Ty::Adt { |
253 | def_id: s.def_id(), | 253 | def_id: s.def_id(), |
254 | name: s.name(db)?, | 254 | name: s |
255 | .name(db)? | ||
256 | .unwrap_or_else(|| SmolStr::new("[unnamed struct]")), | ||
257 | }) | ||
258 | } | ||
259 | |||
260 | pub fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> { | ||
261 | Ok(Ty::Adt { | ||
262 | def_id: s.def_id(), | ||
263 | name: s | ||
264 | .name(db)? | ||
265 | .unwrap_or_else(|| SmolStr::new("[unnamed enum]")), | ||
255 | }) | 266 | }) |
256 | } | 267 | } |
257 | 268 | ||
@@ -264,10 +275,7 @@ pub fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> { | |||
264 | } | 275 | } |
265 | Def::Function(f) => type_for_fn(db, f), | 276 | Def::Function(f) => type_for_fn(db, f), |
266 | Def::Struct(s) => type_for_struct(db, s), | 277 | Def::Struct(s) => type_for_struct(db, s), |
267 | Def::Enum(e) => Ok(Ty::Adt { | 278 | Def::Enum(e) => type_for_enum(db, e), |
268 | def_id, | ||
269 | name: e.name(db)?, | ||
270 | }), | ||
271 | Def::Item => { | 279 | Def::Item => { |
272 | log::debug!("trying to get type for item of unknown type {:?}", def_id); | 280 | log::debug!("trying to get type for item of unknown type {:?}", def_id); |
273 | Ok(Ty::Unknown) | 281 | Ok(Ty::Unknown) |