diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/lib.rs | 48 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/runnables.rs | 2 | ||||
-rw-r--r-- | 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 { | |||
552 | Module { id: self.id.lookup(db.upcast()).container } | 552 | Module { id: self.id.lookup(db.upcast()).container } |
553 | } | 553 | } |
554 | 554 | ||
555 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
556 | Some(self.module(db).krate()) | ||
557 | } | ||
558 | |||
559 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 555 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
560 | db.struct_data(self.id).name.clone() | 556 | db.struct_data(self.id).name.clone() |
561 | } | 557 | } |
@@ -640,10 +636,6 @@ impl Enum { | |||
640 | Module { id: self.id.lookup(db.upcast()).container } | 636 | Module { id: self.id.lookup(db.upcast()).container } |
641 | } | 637 | } |
642 | 638 | ||
643 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
644 | Some(self.module(db).krate()) | ||
645 | } | ||
646 | |||
647 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 639 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
648 | db.enum_data(self.id).name.clone() | 640 | db.enum_data(self.id).name.clone() |
649 | } | 641 | } |
@@ -674,10 +666,6 @@ impl Variant { | |||
674 | self.parent.module(db) | 666 | self.parent.module(db) |
675 | } | 667 | } |
676 | 668 | ||
677 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
678 | self.module(db).krate() | ||
679 | } | ||
680 | |||
681 | pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum { | 669 | pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum { |
682 | self.parent | 670 | self.parent |
683 | } | 671 | } |
@@ -734,10 +722,6 @@ impl Adt { | |||
734 | } | 722 | } |
735 | } | 723 | } |
736 | 724 | ||
737 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
738 | self.module(db).krate() | ||
739 | } | ||
740 | |||
741 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 725 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
742 | match self { | 726 | match self { |
743 | Adt::Struct(s) => s.name(db), | 727 | Adt::Struct(s) => s.name(db), |
@@ -772,10 +756,6 @@ impl VariantDef { | |||
772 | } | 756 | } |
773 | } | 757 | } |
774 | 758 | ||
775 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
776 | self.module(db).krate() | ||
777 | } | ||
778 | |||
779 | pub fn name(&self, db: &dyn HirDatabase) -> Name { | 759 | pub fn name(&self, db: &dyn HirDatabase) -> Name { |
780 | match self { | 760 | match self { |
781 | VariantDef::Struct(s) => s.name(db), | 761 | VariantDef::Struct(s) => s.name(db), |
@@ -830,10 +810,6 @@ impl Function { | |||
830 | self.id.lookup(db.upcast()).module(db.upcast()).into() | 810 | self.id.lookup(db.upcast()).module(db.upcast()).into() |
831 | } | 811 | } |
832 | 812 | ||
833 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
834 | Some(self.module(db).krate()) | ||
835 | } | ||
836 | |||
837 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 813 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
838 | db.function_data(self.id).name.clone() | 814 | db.function_data(self.id).name.clone() |
839 | } | 815 | } |
@@ -1023,10 +999,6 @@ impl Const { | |||
1023 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } | 999 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } |
1024 | } | 1000 | } |
1025 | 1001 | ||
1026 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
1027 | Some(self.module(db).krate()) | ||
1028 | } | ||
1029 | |||
1030 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 1002 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
1031 | db.const_data(self.id).name.clone() | 1003 | db.const_data(self.id).name.clone() |
1032 | } | 1004 | } |
@@ -1054,10 +1026,6 @@ impl Static { | |||
1054 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } | 1026 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } |
1055 | } | 1027 | } |
1056 | 1028 | ||
1057 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
1058 | Some(self.module(db).krate()) | ||
1059 | } | ||
1060 | |||
1061 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 1029 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
1062 | db.static_data(self.id).name.clone() | 1030 | db.static_data(self.id).name.clone() |
1063 | } | 1031 | } |
@@ -1083,10 +1051,6 @@ impl Trait { | |||
1083 | Module { id: self.id.lookup(db.upcast()).container } | 1051 | Module { id: self.id.lookup(db.upcast()).container } |
1084 | } | 1052 | } |
1085 | 1053 | ||
1086 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
1087 | self.module(db).krate() | ||
1088 | } | ||
1089 | |||
1090 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 1054 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
1091 | db.trait_data(self.id).name.clone() | 1055 | db.trait_data(self.id).name.clone() |
1092 | } | 1056 | } |
@@ -1125,10 +1089,6 @@ impl TypeAlias { | |||
1125 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } | 1089 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } |
1126 | } | 1090 | } |
1127 | 1091 | ||
1128 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
1129 | self.module(db).krate() | ||
1130 | } | ||
1131 | |||
1132 | pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> { | 1092 | pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> { |
1133 | db.type_alias_data(self.id).type_ref.as_deref().cloned() | 1093 | db.type_alias_data(self.id).type_ref.as_deref().cloned() |
1134 | } | 1094 | } |
@@ -1191,10 +1151,6 @@ impl MacroDef { | |||
1191 | Some(Module { id: def_map.module_id(module_id) }) | 1151 | Some(Module { id: def_map.module_id(module_id) }) |
1192 | } | 1152 | } |
1193 | 1153 | ||
1194 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
1195 | self.module(db).map(Module::krate) | ||
1196 | } | ||
1197 | |||
1198 | /// XXX: this parses the file | 1154 | /// XXX: this parses the file |
1199 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 1155 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
1200 | match self.source(db)?.value { | 1156 | match self.source(db)?.value { |
@@ -1684,10 +1640,6 @@ impl Impl { | |||
1684 | self.id.lookup(db.upcast()).container.into() | 1640 | self.id.lookup(db.upcast()).container.into() |
1685 | } | 1641 | } |
1686 | 1642 | ||
1687 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
1688 | Crate { id: self.module(db).id.krate() } | ||
1689 | } | ||
1690 | |||
1691 | pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> { | 1643 | pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> { |
1692 | let src = self.source(db)?; | 1644 | let src = self.source(db)?; |
1693 | let item = src.file_id.is_builtin_derive(db.upcast())?; | 1645 | 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( | |||
219 | ) -> Option<SmolStr> { | 219 | ) -> Option<SmolStr> { |
220 | let db = sema.db; | 220 | let db = sema.db; |
221 | let strukt = ty.strip_references().as_adt()?; | 221 | let strukt = ty.strip_references().as_adt()?; |
222 | let krate = strukt.krate(db); | 222 | let krate = strukt.module(db).krate(); |
223 | if krate != famous_defs.core()? { | 223 | if krate != famous_defs.core()? { |
224 | return None; | 224 | return None; |
225 | } | 225 | } |
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<RootDatabase>, def: hir::Function) -> | |||
227 | let func = def.source(sema.db)?; | 227 | let func = def.source(sema.db)?; |
228 | let name_string = def.name(sema.db).to_string(); | 228 | let name_string = def.name(sema.db).to_string(); |
229 | 229 | ||
230 | let root = def.krate(sema.db)?.root_module(sema.db); | 230 | let root = def.module(sema.db).krate().root_module(sema.db); |
231 | 231 | ||
232 | let kind = if name_string == "main" && def.module(sema.db) == root { | 232 | let kind = if name_string == "main" && def.module(sema.db) == root { |
233 | RunnableKind::Bin | 233 | 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<hir::Crate>, def: Definition) | |||
287 | Definition::Macro(m) => { | 287 | Definition::Macro(m) => { |
288 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Macro)); | 288 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Macro)); |
289 | 289 | ||
290 | if m.krate(db) != krate { | 290 | if m.module(db).map(hir::Module::krate) != krate { |
291 | h |= HlMod::Foreign; | 291 | h |= HlMod::Foreign; |
292 | } | 292 | } |
293 | 293 | ||
@@ -296,7 +296,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
296 | Definition::Field(field) => { | 296 | Definition::Field(field) => { |
297 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Field)); | 297 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Field)); |
298 | 298 | ||
299 | if Some(field.parent_def(db).krate(db)) != krate { | 299 | if Some(field.parent_def(db).module(db).krate()) != krate { |
300 | h |= HlMod::Foreign; | 300 | h |= HlMod::Foreign; |
301 | } | 301 | } |
302 | 302 | ||
@@ -335,7 +335,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
335 | if func.is_async(db) { | 335 | if func.is_async(db) { |
336 | h |= HlMod::Async; | 336 | h |= HlMod::Async; |
337 | } | 337 | } |
338 | if func.krate(db) != krate { | 338 | if Some(func.module(db).krate()) != krate { |
339 | h |= HlMod::Foreign; | 339 | h |= HlMod::Foreign; |
340 | } | 340 | } |
341 | return h; | 341 | return h; |
@@ -348,7 +348,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
348 | }; | 348 | }; |
349 | let mut h = Highlight::new(h); | 349 | let mut h = Highlight::new(h); |
350 | 350 | ||
351 | if Some(adt.krate(db)) != krate { | 351 | if Some(adt.module(db).krate()) != krate { |
352 | h |= HlMod::Foreign; | 352 | h |= HlMod::Foreign; |
353 | } | 353 | } |
354 | 354 | ||
@@ -357,7 +357,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
357 | hir::ModuleDef::Variant(variant) => { | 357 | hir::ModuleDef::Variant(variant) => { |
358 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Variant)); | 358 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Variant)); |
359 | 359 | ||
360 | if Some(variant.krate(db)) != krate { | 360 | if Some(variant.module(db).krate()) != krate { |
361 | h |= HlMod::Foreign; | 361 | h |= HlMod::Foreign; |
362 | } | 362 | } |
363 | 363 | ||
@@ -380,7 +380,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
380 | } | 380 | } |
381 | } | 381 | } |
382 | 382 | ||
383 | if konst.krate(db) != krate { | 383 | if Some(konst.module(db).krate()) != krate { |
384 | h |= HlMod::Foreign; | 384 | h |= HlMod::Foreign; |
385 | } | 385 | } |
386 | 386 | ||
@@ -393,7 +393,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
393 | h |= HlMod::Unsafe; | 393 | h |= HlMod::Unsafe; |
394 | } | 394 | } |
395 | 395 | ||
396 | if Some(trait_.krate(db)) != krate { | 396 | if Some(trait_.module(db).krate()) != krate { |
397 | h |= HlMod::Foreign; | 397 | h |= HlMod::Foreign; |
398 | } | 398 | } |
399 | 399 | ||
@@ -416,7 +416,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
416 | } | 416 | } |
417 | } | 417 | } |
418 | 418 | ||
419 | if Some(type_.krate(db)) != krate { | 419 | if Some(type_.module(db).krate()) != krate { |
420 | h |= HlMod::Foreign; | 420 | h |= HlMod::Foreign; |
421 | } | 421 | } |
422 | 422 | ||
@@ -431,7 +431,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
431 | h |= HlMod::Unsafe; | 431 | h |= HlMod::Unsafe; |
432 | } | 432 | } |
433 | 433 | ||
434 | if s.krate(db) != krate { | 434 | if Some(s.module(db).krate()) != krate { |
435 | h |= HlMod::Foreign; | 435 | h |= HlMod::Foreign; |
436 | } | 436 | } |
437 | 437 | ||