aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/method_resolution.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-02-28 00:20:04 +0000
committerLukas Wirth <[email protected]>2021-02-28 00:20:04 +0000
commit5183c9f08345c664237ae138e86f96ff46714f15 (patch)
treea0e660cb49fd67951ee2209d9fc75a2108243df7 /crates/hir_ty/src/method_resolution.rs
parent2a4076c14d0e3f7ae03908c2b9cd1a52851d401c (diff)
Introduce TypeCtor::Scalar
Diffstat (limited to 'crates/hir_ty/src/method_resolution.rs')
-rw-r--r--crates/hir_ty/src/method_resolution.rs90
1 files changed, 26 insertions, 64 deletions
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index b3d1fe9a4..3c817701d 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -7,11 +7,8 @@ use std::{iter, sync::Arc};
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use base_db::CrateId; 8use base_db::CrateId;
9use hir_def::{ 9use hir_def::{
10 builtin_type::{IntBitness, Signedness}, 10 lang_item::LangItemTarget, type_ref::Mutability, AssocContainerId, AssocItemId, FunctionId,
11 lang_item::LangItemTarget, 11 GenericDefId, HasModule, ImplId, Lookup, ModuleId, TraitId,
12 type_ref::Mutability,
13 AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule, ImplId, Lookup, ModuleId,
14 TraitId,
15}; 12};
16use hir_expand::name::Name; 13use hir_expand::name::Name;
17use rustc_hash::{FxHashMap, FxHashSet}; 14use rustc_hash::{FxHashMap, FxHashSet};
@@ -19,10 +16,10 @@ use rustc_hash::{FxHashMap, FxHashSet};
19use crate::{ 16use crate::{
20 autoderef, 17 autoderef,
21 db::HirDatabase, 18 db::HirDatabase,
22 primitive::{FloatBitness, FloatTy, IntTy}, 19 primitive::{FloatTy, IntTy, UintTy},
23 utils::all_super_traits, 20 utils::all_super_traits,
24 ApplicationTy, Canonical, DebruijnIndex, InEnvironment, Substs, TraitEnvironment, TraitRef, Ty, 21 ApplicationTy, Canonical, DebruijnIndex, InEnvironment, Scalar, Substs, TraitEnvironment,
25 TyKind, TypeCtor, TypeWalk, 22 TraitRef, Ty, TyKind, TypeCtor, TypeWalk,
26}; 23};
27 24
28/// This is used as a key for indexing impls. 25/// This is used as a key for indexing impls.
@@ -46,59 +43,23 @@ impl TyFingerprint {
46} 43}
47 44
48pub(crate) const ALL_INT_FPS: [TyFingerprint; 12] = [ 45pub(crate) const ALL_INT_FPS: [TyFingerprint; 12] = [
49 TyFingerprint::Apply(TypeCtor::Int(IntTy { 46 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Int(IntTy::I8))),
50 signedness: Signedness::Unsigned, 47 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Int(IntTy::I16))),
51 bitness: IntBitness::X8, 48 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Int(IntTy::I32))),
52 })), 49 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Int(IntTy::I64))),
53 TyFingerprint::Apply(TypeCtor::Int(IntTy { 50 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Int(IntTy::I128))),
54 signedness: Signedness::Unsigned, 51 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Int(IntTy::Isize))),
55 bitness: IntBitness::X16, 52 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Uint(UintTy::U8))),
56 })), 53 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Uint(UintTy::U16))),
57 TyFingerprint::Apply(TypeCtor::Int(IntTy { 54 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Uint(UintTy::U32))),
58 signedness: Signedness::Unsigned, 55 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Uint(UintTy::U64))),
59 bitness: IntBitness::X32, 56 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Uint(UintTy::U128))),
60 })), 57 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Uint(UintTy::Usize))),
61 TyFingerprint::Apply(TypeCtor::Int(IntTy {
62 signedness: Signedness::Unsigned,
63 bitness: IntBitness::X64,
64 })),
65 TyFingerprint::Apply(TypeCtor::Int(IntTy {
66 signedness: Signedness::Unsigned,
67 bitness: IntBitness::X128,
68 })),
69 TyFingerprint::Apply(TypeCtor::Int(IntTy {
70 signedness: Signedness::Unsigned,
71 bitness: IntBitness::Xsize,
72 })),
73 TyFingerprint::Apply(TypeCtor::Int(IntTy {
74 signedness: Signedness::Signed,
75 bitness: IntBitness::X8,
76 })),
77 TyFingerprint::Apply(TypeCtor::Int(IntTy {
78 signedness: Signedness::Signed,
79 bitness: IntBitness::X16,
80 })),
81 TyFingerprint::Apply(TypeCtor::Int(IntTy {
82 signedness: Signedness::Signed,
83 bitness: IntBitness::X32,
84 })),
85 TyFingerprint::Apply(TypeCtor::Int(IntTy {
86 signedness: Signedness::Signed,
87 bitness: IntBitness::X64,
88 })),
89 TyFingerprint::Apply(TypeCtor::Int(IntTy {
90 signedness: Signedness::Signed,
91 bitness: IntBitness::X128,
92 })),
93 TyFingerprint::Apply(TypeCtor::Int(IntTy {
94 signedness: Signedness::Signed,
95 bitness: IntBitness::Xsize,
96 })),
97]; 58];
98 59
99pub(crate) const ALL_FLOAT_FPS: [TyFingerprint; 2] = [ 60pub(crate) const ALL_FLOAT_FPS: [TyFingerprint; 2] = [
100 TyFingerprint::Apply(TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 })), 61 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Float(FloatTy::F32))),
101 TyFingerprint::Apply(TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 })), 62 TyFingerprint::Apply(TypeCtor::Scalar(Scalar::Float(FloatTy::F64))),
102]; 63];
103 64
104/// Trait impls defined or available in some crate. 65/// Trait impls defined or available in some crate.
@@ -257,14 +218,15 @@ impl Ty {
257 TypeCtor::ForeignType(type_alias_id) => { 218 TypeCtor::ForeignType(type_alias_id) => {
258 return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast())); 219 return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast()));
259 } 220 }
260 TypeCtor::Bool => lang_item_crate!("bool"), 221 TypeCtor::Scalar(Scalar::Bool) => lang_item_crate!("bool"),
261 TypeCtor::Char => lang_item_crate!("char"), 222 TypeCtor::Scalar(Scalar::Char) => lang_item_crate!("char"),
262 TypeCtor::Float(f) => match f.bitness { 223 TypeCtor::Scalar(Scalar::Float(f)) => match f {
263 // There are two lang items: one in libcore (fXX) and one in libstd (fXX_runtime) 224 // There are two lang items: one in libcore (fXX) and one in libstd (fXX_runtime)
264 FloatBitness::X32 => lang_item_crate!("f32", "f32_runtime"), 225 FloatTy::F32 => lang_item_crate!("f32", "f32_runtime"),
265 FloatBitness::X64 => lang_item_crate!("f64", "f64_runtime"), 226 FloatTy::F64 => lang_item_crate!("f64", "f64_runtime"),
266 }, 227 },
267 TypeCtor::Int(i) => lang_item_crate!(i.ty_to_string()), 228 TypeCtor::Scalar(Scalar::Int(t)) => lang_item_crate!(t.ty_to_string()),
229 TypeCtor::Scalar(Scalar::Uint(t)) => lang_item_crate!(t.ty_to_string()),
268 TypeCtor::Str => lang_item_crate!("str_alloc", "str"), 230 TypeCtor::Str => lang_item_crate!("str_alloc", "str"),
269 TypeCtor::Slice => lang_item_crate!("slice_alloc", "slice"), 231 TypeCtor::Slice => lang_item_crate!("slice_alloc", "slice"),
270 TypeCtor::RawPtr(Mutability::Shared) => lang_item_crate!("const_ptr"), 232 TypeCtor::RawPtr(Mutability::Shared) => lang_item_crate!("const_ptr"),