From c32428571c3fbf12bd4a4187c797488355416a18 Mon Sep 17 00:00:00 2001 From: Aramis Razzaghipour Date: Mon, 24 May 2021 09:42:06 +1000 Subject: Remove hir krate methods --- crates/hir/src/lib.rs | 48 ------------------------- crates/ide/src/inlay_hints.rs | 2 +- crates/ide/src/runnables.rs | 2 +- crates/ide/src/syntax_highlighting/highlight.rs | 18 +++++----- 4 files changed, 11 insertions(+), 59 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 6522a924b..ec5f0c53d 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -552,10 +552,6 @@ impl Struct { Module { id: self.id.lookup(db.upcast()).container } } - pub fn krate(self, db: &dyn HirDatabase) -> Option { - Some(self.module(db).krate()) - } - pub fn name(self, db: &dyn HirDatabase) -> Name { db.struct_data(self.id).name.clone() } @@ -640,10 +636,6 @@ impl Enum { Module { id: self.id.lookup(db.upcast()).container } } - pub fn krate(self, db: &dyn HirDatabase) -> Option { - Some(self.module(db).krate()) - } - pub fn name(self, db: &dyn HirDatabase) -> Name { db.enum_data(self.id).name.clone() } @@ -674,10 +666,6 @@ impl Variant { 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 { 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 { match self { 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 { match self { VariantDef::Struct(s) => s.name(db), @@ -830,10 +810,6 @@ impl Function { self.id.lookup(db.upcast()).module(db.upcast()).into() } - pub fn krate(self, db: &dyn HirDatabase) -> Option { - Some(self.module(db).krate()) - } - pub fn name(self, db: &dyn HirDatabase) -> Name { db.function_data(self.id).name.clone() } @@ -1023,10 +999,6 @@ impl Const { Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } } - pub fn krate(self, db: &dyn HirDatabase) -> Option { - Some(self.module(db).krate()) - } - pub fn name(self, db: &dyn HirDatabase) -> Option { db.const_data(self.id).name.clone() } @@ -1054,10 +1026,6 @@ impl Static { Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } } - pub fn krate(self, db: &dyn HirDatabase) -> Option { - Some(self.module(db).krate()) - } - pub fn name(self, db: &dyn HirDatabase) -> Option { db.static_data(self.id).name.clone() } @@ -1083,10 +1051,6 @@ impl Trait { 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 { db.trait_data(self.id).name.clone() } @@ -1125,10 +1089,6 @@ impl TypeAlias { 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 { 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) }) } - pub fn krate(self, db: &dyn HirDatabase) -> Option { - self.module(db).map(Module::krate) - } - /// XXX: this parses the file pub fn name(self, db: &dyn HirDatabase) -> Option { match self.source(db)?.value { @@ -1684,10 +1640,6 @@ impl Impl { 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> { let src = self.source(db)?; let item = src.file_id.is_builtin_derive(db.upcast())?; diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 960d169f4..0ada3f92b 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -219,7 +219,7 @@ fn hint_iterator( ) -> Option { let db = sema.db; let strukt = ty.strip_references().as_adt()?; - let krate = strukt.krate(db); + let krate = strukt.module(db).krate(); if krate != famous_defs.core()? { return None; } diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index f76715d84..ce1c76f37 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -227,7 +227,7 @@ pub(crate) fn runnable_fn(sema: &Semantics, def: hir::Function) -> let func = def.source(sema.db)?; 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 { RunnableKind::Bin diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 2d6d8d100..574a14429 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -287,7 +287,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) Definition::Macro(m) => { 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; } @@ -296,7 +296,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) Definition::Field(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; } @@ -335,7 +335,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) if func.is_async(db) { h |= HlMod::Async; } - if func.krate(db) != krate { + if Some(func.module(db).krate()) != krate { h |= HlMod::Foreign; } return h; @@ -348,7 +348,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) }; let mut h = Highlight::new(h); - if Some(adt.krate(db)) != krate { + if Some(adt.module(db).krate()) != krate { h |= HlMod::Foreign; } @@ -357,7 +357,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) hir::ModuleDef::Variant(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; } @@ -380,7 +380,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) } } - if konst.krate(db) != krate { + if Some(konst.module(db).krate()) != krate { h |= HlMod::Foreign; } @@ -393,7 +393,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) h |= HlMod::Unsafe; } - if Some(trait_.krate(db)) != krate { + if Some(trait_.module(db).krate()) != krate { h |= HlMod::Foreign; } @@ -416,7 +416,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) } } - if Some(type_.krate(db)) != krate { + if Some(type_.module(db).krate()) != krate { h |= HlMod::Foreign; } @@ -431,7 +431,7 @@ fn highlight_def(db: &RootDatabase, krate: Option, def: Definition) h |= HlMod::Unsafe; } - if s.krate(db) != krate { + if Some(s.module(db).krate()) != krate { h |= HlMod::Foreign; } -- cgit v1.2.3