Remove hir krate methods

This commit is contained in:
Aramis Razzaghipour 2021-05-24 09:42:06 +10:00
parent 4fd5248749
commit c32428571c
No known key found for this signature in database
GPG key ID: F788F7E990136003
4 changed files with 11 additions and 59 deletions

View file

@ -552,10 +552,6 @@ impl Struct {
Module { id: self.id.lookup(db.upcast()).container } Module { id: self.id.lookup(db.upcast()).container }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
Some(self.module(db).krate())
}
pub fn name(self, db: &dyn HirDatabase) -> Name { pub fn name(self, db: &dyn HirDatabase) -> Name {
db.struct_data(self.id).name.clone() db.struct_data(self.id).name.clone()
} }
@ -640,10 +636,6 @@ impl Enum {
Module { id: self.id.lookup(db.upcast()).container } Module { id: self.id.lookup(db.upcast()).container }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
Some(self.module(db).krate())
}
pub fn name(self, db: &dyn HirDatabase) -> Name { pub fn name(self, db: &dyn HirDatabase) -> Name {
db.enum_data(self.id).name.clone() db.enum_data(self.id).name.clone()
} }
@ -674,10 +666,6 @@ impl Variant {
self.parent.module(db) self.parent.module(db)
} }
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
self.module(db).krate()
}
pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum { pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum {
self.parent self.parent
} }
@ -734,10 +722,6 @@ impl Adt {
} }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
self.module(db).krate()
}
pub fn name(self, db: &dyn HirDatabase) -> Name { pub fn name(self, db: &dyn HirDatabase) -> Name {
match self { match self {
Adt::Struct(s) => s.name(db), Adt::Struct(s) => s.name(db),
@ -772,10 +756,6 @@ impl VariantDef {
} }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
self.module(db).krate()
}
pub fn name(&self, db: &dyn HirDatabase) -> Name { pub fn name(&self, db: &dyn HirDatabase) -> Name {
match self { match self {
VariantDef::Struct(s) => s.name(db), VariantDef::Struct(s) => s.name(db),
@ -830,10 +810,6 @@ impl Function {
self.id.lookup(db.upcast()).module(db.upcast()).into() self.id.lookup(db.upcast()).module(db.upcast()).into()
} }
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
Some(self.module(db).krate())
}
pub fn name(self, db: &dyn HirDatabase) -> Name { pub fn name(self, db: &dyn HirDatabase) -> Name {
db.function_data(self.id).name.clone() db.function_data(self.id).name.clone()
} }
@ -1023,10 +999,6 @@ impl Const {
Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } Module { id: self.id.lookup(db.upcast()).module(db.upcast()) }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
Some(self.module(db).krate())
}
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
db.const_data(self.id).name.clone() db.const_data(self.id).name.clone()
} }
@ -1054,10 +1026,6 @@ impl Static {
Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } Module { id: self.id.lookup(db.upcast()).module(db.upcast()) }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
Some(self.module(db).krate())
}
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
db.static_data(self.id).name.clone() db.static_data(self.id).name.clone()
} }
@ -1083,10 +1051,6 @@ impl Trait {
Module { id: self.id.lookup(db.upcast()).container } Module { id: self.id.lookup(db.upcast()).container }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
self.module(db).krate()
}
pub fn name(self, db: &dyn HirDatabase) -> Name { pub fn name(self, db: &dyn HirDatabase) -> Name {
db.trait_data(self.id).name.clone() db.trait_data(self.id).name.clone()
} }
@ -1125,10 +1089,6 @@ impl TypeAlias {
Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } Module { id: self.id.lookup(db.upcast()).module(db.upcast()) }
} }
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
self.module(db).krate()
}
pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> { pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> {
db.type_alias_data(self.id).type_ref.as_deref().cloned() db.type_alias_data(self.id).type_ref.as_deref().cloned()
} }
@ -1191,10 +1151,6 @@ impl MacroDef {
Some(Module { id: def_map.module_id(module_id) }) Some(Module { id: def_map.module_id(module_id) })
} }
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
self.module(db).map(Module::krate)
}
/// XXX: this parses the file /// XXX: this parses the file
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
match self.source(db)?.value { match self.source(db)?.value {
@ -1684,10 +1640,6 @@ impl Impl {
self.id.lookup(db.upcast()).container.into() self.id.lookup(db.upcast()).container.into()
} }
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
Crate { id: self.module(db).id.krate() }
}
pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> { pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> {
let src = self.source(db)?; let src = self.source(db)?;
let item = src.file_id.is_builtin_derive(db.upcast())?; let item = src.file_id.is_builtin_derive(db.upcast())?;

View file

@ -219,7 +219,7 @@ fn hint_iterator(
) -> Option<SmolStr> { ) -> Option<SmolStr> {
let db = sema.db; let db = sema.db;
let strukt = ty.strip_references().as_adt()?; let strukt = ty.strip_references().as_adt()?;
let krate = strukt.krate(db); let krate = strukt.module(db).krate();
if krate != famous_defs.core()? { if krate != famous_defs.core()? {
return None; return None;
} }

View file

@ -227,7 +227,7 @@ pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) ->
let func = def.source(sema.db)?; let func = def.source(sema.db)?;
let name_string = def.name(sema.db).to_string(); let name_string = def.name(sema.db).to_string();
let root = def.krate(sema.db)?.root_module(sema.db); let root = def.module(sema.db).krate().root_module(sema.db);
let kind = if name_string == "main" && def.module(sema.db) == root { let kind = if name_string == "main" && def.module(sema.db) == root {
RunnableKind::Bin RunnableKind::Bin

View file

@ -287,7 +287,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
Definition::Macro(m) => { Definition::Macro(m) => {
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Macro)); let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Macro));
if m.krate(db) != krate { if m.module(db).map(hir::Module::krate) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -296,7 +296,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
Definition::Field(field) => { Definition::Field(field) => {
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Field)); let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Field));
if Some(field.parent_def(db).krate(db)) != krate { if Some(field.parent_def(db).module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -335,7 +335,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
if func.is_async(db) { if func.is_async(db) {
h |= HlMod::Async; h |= HlMod::Async;
} }
if func.krate(db) != krate { if Some(func.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
return h; return h;
@ -348,7 +348,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
}; };
let mut h = Highlight::new(h); let mut h = Highlight::new(h);
if Some(adt.krate(db)) != krate { if Some(adt.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -357,7 +357,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
hir::ModuleDef::Variant(variant) => { hir::ModuleDef::Variant(variant) => {
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Variant)); let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Variant));
if Some(variant.krate(db)) != krate { if Some(variant.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -380,7 +380,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
} }
} }
if konst.krate(db) != krate { if Some(konst.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -393,7 +393,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
h |= HlMod::Unsafe; h |= HlMod::Unsafe;
} }
if Some(trait_.krate(db)) != krate { if Some(trait_.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -416,7 +416,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
} }
} }
if Some(type_.krate(db)) != krate { if Some(type_.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }
@ -431,7 +431,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
h |= HlMod::Unsafe; h |= HlMod::Unsafe;
} }
if s.krate(db) != krate { if Some(s.module(db).krate()) != krate {
h |= HlMod::Foreign; h |= HlMod::Foreign;
} }