about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOleStrohm <strohm99@gmail.com>2022-08-06 19:12:57 +0200
committerOleStrohm <strohm99@gmail.com>2022-09-12 20:19:49 +0100
commitb63234e20be04ae0e7eca20e0bf49dca8d7d3718 (patch)
treea67b5cf7257718f1cfee821e0592cfd50526fb3d
parente28046c673178361d39b7f6dafd6915767f2d71f (diff)
downloadrust-b63234e20be04ae0e7eca20e0bf49dca8d7d3718.tar.gz
rust-b63234e20be04ae0e7eca20e0bf49dca8d7d3718.zip
Cleaned up code
-rw-r--r--crates/hir-ty/src/infer.rs6
-rw-r--r--crates/hir/src/lib.rs14
-rw-r--r--crates/hir/src/symbols.rs5
-rw-r--r--crates/ide/src/hover/render.rs5
4 files changed, 14 insertions, 16 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 63d0f1b01cf..c821a3786b9 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -26,7 +26,7 @@ use hir_def::{
     resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs},
     type_ref::TypeRef,
     AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, HasModule, Lookup,
-    TraitId, TypeAliasId, VariantId,
+    TraitId, TypeAliasId, VariantId
 };
 use hir_expand::name::{name, Name};
 use itertools::Either;
@@ -68,10 +68,6 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
         DefWithBodyId::FunctionId(f) => ctx.collect_fn(f),
         DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)),
         DefWithBodyId::VariantId(v) => {
-            //let def = AttrDefId::EnumVariantId(v);
-            //let attrs = db.attrs(def);
-            //let repr = attrs.by_key("repr").attrs().next().unwrap();
-            //let ident = repr.single_ident_value().unwrap().text;
             // TODO(ole): Get the real type
             ctx.return_ty = TyBuilder::def_ty(db, v.parent.into()).fill_with_unknown().build()
         }
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 258224a7584..1b06dbd9085 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -967,11 +967,6 @@ pub struct Variant {
 }
 
 impl Variant {
-    pub fn value(self, db: &dyn HirDatabase) -> Option<Expr> {
-        // TODO(ole): Handle missing exprs (+1 to the prev)
-        self.source(db)?.value.expr()
-    }
-
     pub fn module(self, db: &dyn HirDatabase) -> Module {
         self.parent.module(db)
     }
@@ -999,6 +994,15 @@ impl Variant {
     pub(crate) fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> {
         db.enum_data(self.parent.id).variants[self.id].variant_data.clone()
     }
+
+    pub fn value(self, db: &dyn HirDatabase) -> Option<Expr> {
+        // TODO(ole): Handle missing exprs (+1 to the prev)
+        self.source(db)?.value.expr()
+    }
+
+    pub fn eval(self, db: &dyn HirDatabase) -> Result<ComputedExpr, ConstEvalError> {
+        db.const_eval_variant(self.into())
+    }
 }
 
 /// Variants inherit visibility from the parent enum.
diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs
index 8432f0e7e01..fd78decda4e 100644
--- a/crates/hir/src/symbols.rs
+++ b/crates/hir/src/symbols.rs
@@ -1,7 +1,6 @@
 //! File symbol extraction.
 
 use base_db::FileRange;
-use hir_def::db::DefDatabase;
 use hir_def::{
     item_tree::ItemTreeNode, src::HasSource, AdtId, AssocItemId, AssocItemLoc, DefWithBodyId,
     HasModule, ImplId, ItemContainerId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId,
@@ -246,8 +245,8 @@ impl<'a> SymbolCollector<'a> {
                 id.lookup(self.db.upcast()).source(self.db.upcast()).value.name()?.text().into(),
             ),
             DefWithBodyId::VariantId(id) => Some({
-                let up_db: &dyn DefDatabase = self.db.upcast();
-                up_db.lookup_intern_enum(id.parent).source(up_db).value.name()?.text().into()
+                let db = self.db.upcast();
+                id.parent.lookup(db).source(db).value.name()?.text().into()
             }),
         }
     }
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index cd63131e7a7..8ac268f2438 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -349,11 +349,10 @@ pub(super) fn definition(
         Definition::Function(it) => label_and_docs(db, it),
         Definition::Adt(it) => label_and_docs(db, it),
         Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
-            let hir_db: &dyn HirDatabase = db;
-            let body = hir_db.const_eval_variant(it.into());
+            let body = it.eval(db);
             match body {
                 Ok(x) => Some(format!("{}", x)),
-                Err(_) => it.value(db).map(|s| format!("{}", s)),
+                Err(_) => it.value(db).map(|x| format!("{}", x)),
             }
         }),
         Definition::Const(it) => label_value_and_docs(db, it, |it| {