aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/code_model.rs20
-rw-r--r--crates/hir/src/from_id.rs21
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/hir/src/source_analyzer.rs9
4 files changed, 41 insertions, 11 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index e9bb4f541..35b532602 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -6,7 +6,6 @@ use base_db::{CrateDisplayName, CrateId, Edition, FileId};
6use either::Either; 6use either::Either;
7use hir_def::{ 7use hir_def::{
8 adt::{ReprKind, StructKind, VariantData}, 8 adt::{ReprKind, StructKind, VariantData},
9 builtin_type::BuiltinType,
10 expr::{BindingAnnotation, LabelId, Pat, PatId}, 9 expr::{BindingAnnotation, LabelId, Pat, PatId},
11 import_map, 10 import_map,
12 item_tree::ItemTreeNode, 11 item_tree::ItemTreeNode,
@@ -245,7 +244,7 @@ impl ModuleDef {
245 ModuleDef::Const(it) => it.name(db), 244 ModuleDef::Const(it) => it.name(db),
246 ModuleDef::Static(it) => it.name(db), 245 ModuleDef::Static(it) => it.name(db),
247 246
248 ModuleDef::BuiltinType(it) => Some(it.as_name()), 247 ModuleDef::BuiltinType(it) => Some(it.name()),
249 } 248 }
250 } 249 }
251 250
@@ -995,6 +994,23 @@ impl HasVisibility for TypeAlias {
995} 994}
996 995
997#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 996#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
997pub struct BuiltinType {
998 pub(crate) inner: hir_def::builtin_type::BuiltinType,
999}
1000
1001impl BuiltinType {
1002 pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type {
1003 let resolver = module.id.resolver(db.upcast());
1004 Type::new_with_resolver(db, &resolver, Ty::builtin(self.inner))
1005 .expect("crate not present in resolver")
1006 }
1007
1008 pub fn name(self) -> Name {
1009 self.inner.as_name()
1010 }
1011}
1012
1013#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
998pub struct MacroDef { 1014pub struct MacroDef {
999 pub(crate) id: MacroDefId, 1015 pub(crate) id: MacroDefId,
1000} 1016}
diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs
index c8c5fecd7..b5814da11 100644
--- a/crates/hir/src/from_id.rs
+++ b/crates/hir/src/from_id.rs
@@ -11,8 +11,9 @@ use hir_def::{
11}; 11};
12 12
13use crate::{ 13use crate::{
14 code_model::GenericParam, Adt, AssocItem, DefWithBody, Field, GenericDef, Label, Local, 14 code_model::{BuiltinType, GenericParam},
15 MacroDef, ModuleDef, Variant, VariantDef, 15 Adt, AssocItem, DefWithBody, Field, GenericDef, Label, Local, MacroDef, ModuleDef, Variant,
16 VariantDef,
16}; 17};
17 18
18macro_rules! from_id { 19macro_rules! from_id {
@@ -111,7 +112,7 @@ impl From<ModuleDefId> for ModuleDef {
111 ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()), 112 ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()),
112 ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()), 113 ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()),
113 ModuleDefId::TypeAliasId(it) => ModuleDef::TypeAlias(it.into()), 114 ModuleDefId::TypeAliasId(it) => ModuleDef::TypeAlias(it.into()),
114 ModuleDefId::BuiltinType(it) => ModuleDef::BuiltinType(it), 115 ModuleDefId::BuiltinType(it) => ModuleDef::BuiltinType(it.into()),
115 } 116 }
116 } 117 }
117} 118}
@@ -127,7 +128,7 @@ impl From<ModuleDef> for ModuleDefId {
127 ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()), 128 ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()),
128 ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()), 129 ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()),
129 ModuleDef::TypeAlias(it) => ModuleDefId::TypeAliasId(it.into()), 130 ModuleDef::TypeAlias(it) => ModuleDefId::TypeAliasId(it.into()),
130 ModuleDef::BuiltinType(it) => ModuleDefId::BuiltinType(it), 131 ModuleDef::BuiltinType(it) => ModuleDefId::BuiltinType(it.into()),
131 } 132 }
132 } 133 }
133} 134}
@@ -274,3 +275,15 @@ impl From<ModuleDef> for ItemInNs {
274 } 275 }
275 } 276 }
276} 277}
278
279impl From<hir_def::builtin_type::BuiltinType> for BuiltinType {
280 fn from(inner: hir_def::builtin_type::BuiltinType) -> Self {
281 Self { inner }
282 }
283}
284
285impl From<BuiltinType> for hir_def::builtin_type::BuiltinType {
286 fn from(it: BuiltinType) -> Self {
287 it.inner
288 }
289}
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 0a30b4f5b..59292d5a2 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -49,7 +49,7 @@ impl PathResolution {
49 match self { 49 match self {
50 PathResolution::Def(ModuleDef::Adt(adt)) => Some(TypeNs::AdtId((*adt).into())), 50 PathResolution::Def(ModuleDef::Adt(adt)) => Some(TypeNs::AdtId((*adt).into())),
51 PathResolution::Def(ModuleDef::BuiltinType(builtin)) => { 51 PathResolution::Def(ModuleDef::BuiltinType(builtin)) => {
52 Some(TypeNs::BuiltinType(*builtin)) 52 Some(TypeNs::BuiltinType((*builtin).into()))
53 } 53 }
54 PathResolution::Def(ModuleDef::Const(_)) 54 PathResolution::Def(ModuleDef::Const(_))
55 | PathResolution::Def(ModuleDef::Variant(_)) 55 | PathResolution::Def(ModuleDef::Variant(_))
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index bed3fa50f..dc21f6051 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -28,8 +28,9 @@ use syntax::{
28}; 28};
29 29
30use crate::{ 30use crate::{
31 db::HirDatabase, semantics::PathResolution, Adt, Const, Field, Function, Local, MacroDef, 31 code_model::BuiltinType, db::HirDatabase, semantics::PathResolution, Adt, Const, Field,
32 ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Variant, 32 Function, Local, MacroDef, ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam,
33 Variant,
33}; 34};
34use base_db::CrateId; 35use base_db::CrateId;
35 36
@@ -479,7 +480,7 @@ fn resolve_hir_path_(
479 } 480 }
480 TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), 481 TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
481 TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), 482 TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
482 TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), 483 TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
483 TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), 484 TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
484 }) 485 })
485 }; 486 };
@@ -555,7 +556,7 @@ fn resolve_hir_path_qualifier(
555 TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()), 556 TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()),
556 TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), 557 TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
557 TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), 558 TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
558 TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), 559 TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
559 TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), 560 TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
560 }) 561 })
561} 562}