Cleaned up code
This commit is contained in:
parent
e28046c673
commit
b63234e20b
@ -26,7 +26,7 @@
|
||||
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()
|
||||
}
|
||||
|
@ -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 @@ pub fn kind(self, db: &dyn HirDatabase) -> StructKind {
|
||||
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.
|
||||
|
@ -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 @@ fn def_with_body_id_name(&self, body_id: DefWithBodyId) -> Option<SmolStr> {
|
||||
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()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -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| {
|
||||
|
Loading…
Reference in New Issue
Block a user