aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs43
1 files changed, 40 insertions, 3 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 69496b624..e3c765674 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -4,12 +4,12 @@ use ra_db::{CrateId, SourceRootId, Edition, FileId};
4use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc}; 4use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc};
5 5
6use crate::{ 6use crate::{
7 Name, AsName, AstId, Ty, HirFileId, Either, 7 Name, AsName, AstId, Ty, HirFileId, Either, KnownName,
8 HirDatabase, DefDatabase, 8 HirDatabase, DefDatabase,
9 type_ref::TypeRef, 9 type_ref::TypeRef,
10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
11 expr::{Body, BodySourceMap, validation::ExprValidator}, 11 expr::{Body, BodySourceMap, validation::ExprValidator},
12 ty::{TraitRef, InferenceResult}, 12 ty::{TraitRef, InferenceResult, primitive::{IntTy, FloatTy, Signedness, IntBitness, FloatBitness}},
13 adt::{EnumVariantId, StructFieldId, VariantDef}, 13 adt::{EnumVariantId, StructFieldId, VariantDef},
14 generics::HasGenericParams, 14 generics::HasGenericParams,
15 docs::{Documentation, Docs, docs_from_ast}, 15 docs::{Documentation, Docs, docs_from_ast},
@@ -75,6 +75,41 @@ pub struct Module {
75 pub(crate) module_id: CrateModuleId, 75 pub(crate) module_id: CrateModuleId,
76} 76}
77 77
78#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
79pub enum BuiltinType {
80 Char,
81 Bool,
82 Str,
83 Int(IntTy),
84 Float(FloatTy),
85}
86
87impl BuiltinType {
88 #[rustfmt::skip]
89 pub(crate) const ALL: &'static [(KnownName, BuiltinType)] = &[
90 (KnownName::Char, BuiltinType::Char),
91 (KnownName::Bool, BuiltinType::Bool),
92 (KnownName::Str, BuiltinType::Str),
93
94 (KnownName::Isize, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })),
95 (KnownName::I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })),
96 (KnownName::I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })),
97 (KnownName::I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })),
98 (KnownName::I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })),
99 (KnownName::I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })),
100
101 (KnownName::Usize, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })),
102 (KnownName::U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })),
103 (KnownName::U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })),
104 (KnownName::U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })),
105 (KnownName::U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })),
106 (KnownName::U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })),
107
108 (KnownName::F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })),
109 (KnownName::F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })),
110 ];
111}
112
78/// The defs which can be visible in the module. 113/// The defs which can be visible in the module.
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 114#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
80pub enum ModuleDef { 115pub enum ModuleDef {
@@ -89,6 +124,7 @@ pub enum ModuleDef {
89 Static(Static), 124 Static(Static),
90 Trait(Trait), 125 Trait(Trait),
91 TypeAlias(TypeAlias), 126 TypeAlias(TypeAlias),
127 BuiltinType(BuiltinType),
92} 128}
93impl_froms!( 129impl_froms!(
94 ModuleDef: Module, 130 ModuleDef: Module,
@@ -100,7 +136,8 @@ impl_froms!(
100 Const, 136 Const,
101 Static, 137 Static,
102 Trait, 138 Trait,
103 TypeAlias 139 TypeAlias,
140 BuiltinType
104); 141);
105 142
106pub enum ModuleSource { 143pub enum ModuleSource {