aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/method_resolution.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-28 13:36:44 +0000
committerGitHub <[email protected]>2021-02-28 13:36:44 +0000
commit803ff2e55eeb6bd1d9028fbbffe34721f0e6d459 (patch)
treec0df3cba7d22fe49e1ea33dde6ed8d4c9e0f663f /crates/hir_ty/src/method_resolution.rs
parent7f57a01b3d524a5ed85a30265b8aee2c81118f15 (diff)
parent7c2dd85a32e320fd412a720ea5b847c66bf246ae (diff)
Merge #7804
7804: Introduce TypeCtor::Scalar r=lnicola a=Veykril `TypeCtor::Int(..) | TypeCtor::Float(..) | TypeCtor::Char | TypeCtor::Bool` => `TypeCtor::Scalar(..)`, in this case we can actually just straight up use `chalk_ir::Scalar` already since its just a POD without any IDs or anything. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/method_resolution.rs')
-rw-r--r--crates/hir_ty/src/method_resolution.rs94
1 files changed, 30 insertions, 64 deletions
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index b3d1fe9a4..66d8de959 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::{self, 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,19 @@ 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)) => {
229 lang_item_crate!(primitive::int_ty_to_string(t))
230 }
231 TypeCtor::Scalar(Scalar::Uint(t)) => {
232 lang_item_crate!(primitive::uint_ty_to_string(t))
233 }
268 TypeCtor::Str => lang_item_crate!("str_alloc", "str"), 234 TypeCtor::Str => lang_item_crate!("str_alloc", "str"),
269 TypeCtor::Slice => lang_item_crate!("slice_alloc", "slice"), 235 TypeCtor::Slice => lang_item_crate!("slice_alloc", "slice"),
270 TypeCtor::RawPtr(Mutability::Shared) => lang_item_crate!("const_ptr"), 236 TypeCtor::RawPtr(Mutability::Shared) => lang_item_crate!("const_ptr"),