Skip to content

Commit b63234e

Browse files
committed
Cleaned up code
1 parent e28046c commit b63234e

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use hir_def::{
2626
resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs},
2727
type_ref::TypeRef,
2828
AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, HasModule, Lookup,
29-
TraitId, TypeAliasId, VariantId,
29+
TraitId, TypeAliasId, VariantId
3030
};
3131
use hir_expand::name::{name, Name};
3232
use itertools::Either;
@@ -68,10 +68,6 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
6868
DefWithBodyId::FunctionId(f) => ctx.collect_fn(f),
6969
DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)),
7070
DefWithBodyId::VariantId(v) => {
71-
//let def = AttrDefId::EnumVariantId(v);
72-
//let attrs = db.attrs(def);
73-
//let repr = attrs.by_key("repr").attrs().next().unwrap();
74-
//let ident = repr.single_ident_value().unwrap().text;
7571
// TODO(ole): Get the real type
7672
ctx.return_ty = TyBuilder::def_ty(db, v.parent.into()).fill_with_unknown().build()
7773
}

crates/hir/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -967,11 +967,6 @@ pub struct Variant {
967967
}
968968

969969
impl 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-
975970
pub fn module(self, db: &dyn HirDatabase) -> Module {
976971
self.parent.module(db)
977972
}
@@ -999,6 +994,15 @@ impl Variant {
999994
pub(crate) fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> {
1000995
db.enum_data(self.parent.id).variants[self.id].variant_data.clone()
1001996
}
997+
998+
pub fn value(self, db: &dyn HirDatabase) -> Option<Expr> {
999+
// TODO(ole): Handle missing exprs (+1 to the prev)
1000+
self.source(db)?.value.expr()
1001+
}
1002+
1003+
pub fn eval(self, db: &dyn HirDatabase) -> Result<ComputedExpr, ConstEvalError> {
1004+
db.const_eval_variant(self.into())
1005+
}
10021006
}
10031007

10041008
/// Variants inherit visibility from the parent enum.

crates/hir/src/symbols.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! File symbol extraction.
22
33
use base_db::FileRange;
4-
use hir_def::db::DefDatabase;
54
use hir_def::{
65
item_tree::ItemTreeNode, src::HasSource, AdtId, AssocItemId, AssocItemLoc, DefWithBodyId,
76
HasModule, ImplId, ItemContainerId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId,
@@ -246,8 +245,8 @@ impl<'a> SymbolCollector<'a> {
246245
id.lookup(self.db.upcast()).source(self.db.upcast()).value.name()?.text().into(),
247246
),
248247
DefWithBodyId::VariantId(id) => Some({
249-
let up_db: &dyn DefDatabase = self.db.upcast();
250-
up_db.lookup_intern_enum(id.parent).source(up_db).value.name()?.text().into()
248+
let db = self.db.upcast();
249+
id.parent.lookup(db).source(db).value.name()?.text().into()
251250
}),
252251
}
253252
}

crates/ide/src/hover/render.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,10 @@ pub(super) fn definition(
349349
Definition::Function(it) => label_and_docs(db, it),
350350
Definition::Adt(it) => label_and_docs(db, it),
351351
Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
352-
let hir_db: &dyn HirDatabase = db;
353-
let body = hir_db.const_eval_variant(it.into());
352+
let body = it.eval(db);
354353
match body {
355354
Ok(x) => Some(format!("{}", x)),
356-
Err(_) => it.value(db).map(|s| format!("{}", s)),
355+
Err(_) => it.value(db).map(|x| format!("{}", x)),
357356
}
358357
}),
359358
Definition::Const(it) => label_value_and_docs(db, it, |it| {

0 commit comments

Comments
 (0)