diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 50 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/name.rs | 137 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 15 |
9 files changed, 79 insertions, 161 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6cf2c620d..805357662 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -19,6 +19,10 @@ use crate::{ | |||
19 | TypeAliasId, | 19 | TypeAliasId, |
20 | }, | 20 | }, |
21 | impl_block::ImplBlock, | 21 | impl_block::ImplBlock, |
22 | name::{ | ||
23 | BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64, | ||
24 | U8, USIZE, | ||
25 | }, | ||
22 | nameres::{CrateModuleId, ImportId, ModuleScope, Namespace}, | 26 | nameres::{CrateModuleId, ImportId, ModuleScope, Namespace}, |
23 | resolve::Resolver, | 27 | resolve::Resolver, |
24 | traits::{TraitData, TraitItem}, | 28 | traits::{TraitData, TraitItem}, |
@@ -28,7 +32,7 @@ use crate::{ | |||
28 | }, | 32 | }, |
29 | type_ref::Mutability, | 33 | type_ref::Mutability, |
30 | type_ref::TypeRef, | 34 | type_ref::TypeRef, |
31 | AsName, AstDatabase, AstId, DefDatabase, Either, HasSource, HirDatabase, KnownName, Name, Ty, | 35 | AsName, AstDatabase, AstId, DefDatabase, Either, HasSource, HirDatabase, Name, Ty, |
32 | }; | 36 | }; |
33 | 37 | ||
34 | /// hir::Crate describes a single crate. It's the main interface with which | 38 | /// hir::Crate describes a single crate. It's the main interface with which |
@@ -96,27 +100,27 @@ pub enum BuiltinType { | |||
96 | 100 | ||
97 | impl BuiltinType { | 101 | impl BuiltinType { |
98 | #[rustfmt::skip] | 102 | #[rustfmt::skip] |
99 | pub(crate) const ALL: &'static [(KnownName, BuiltinType)] = &[ | 103 | pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[ |
100 | (KnownName::Char, BuiltinType::Char), | 104 | (CHAR, BuiltinType::Char), |
101 | (KnownName::Bool, BuiltinType::Bool), | 105 | (BOOL, BuiltinType::Bool), |
102 | (KnownName::Str, BuiltinType::Str), | 106 | (STR, BuiltinType::Str), |
103 | 107 | ||
104 | (KnownName::Isize, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), | 108 | (ISIZE, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), |
105 | (KnownName::I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })), | 109 | (I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })), |
106 | (KnownName::I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })), | 110 | (I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })), |
107 | (KnownName::I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })), | 111 | (I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })), |
108 | (KnownName::I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })), | 112 | (I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })), |
109 | (KnownName::I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })), | 113 | (I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })), |
110 | 114 | ||
111 | (KnownName::Usize, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), | 115 | (USIZE, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), |
112 | (KnownName::U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), | 116 | (U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), |
113 | (KnownName::U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), | 117 | (U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), |
114 | (KnownName::U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), | 118 | (U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), |
115 | (KnownName::U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), | 119 | (U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), |
116 | (KnownName::U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), | 120 | (U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), |
117 | 121 | ||
118 | (KnownName::F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), | 122 | (F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), |
119 | (KnownName::F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })), | 123 | (F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })), |
120 | ]; | 124 | ]; |
121 | } | 125 | } |
122 | 126 | ||
@@ -560,7 +564,7 @@ impl FnData { | |||
560 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | 564 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { |
561 | TypeRef::from_ast(type_ref) | 565 | TypeRef::from_ast(type_ref) |
562 | } else { | 566 | } else { |
563 | let self_type = TypeRef::Path(Name::self_type().into()); | 567 | let self_type = TypeRef::Path(SELF_TYPE.into()); |
564 | match self_param.kind() { | 568 | match self_param.kind() { |
565 | ast::SelfParamKind::Owned => self_type, | 569 | ast::SelfParamKind::Owned => self_type, |
566 | ast::SelfParamKind::Ref => { | 570 | ast::SelfParamKind::Ref => { |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 3e763fef0..3a97d97ce 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -13,7 +13,7 @@ use ra_syntax::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | name::AsName, | 16 | name::{AsName, SELF_PARAM}, |
17 | type_ref::{Mutability, TypeRef}, | 17 | type_ref::{Mutability, TypeRef}, |
18 | DefWithBody, Either, HasSource, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Name, | 18 | DefWithBody, Either, HasSource, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Name, |
19 | Path, Resolver, | 19 | Path, Resolver, |
@@ -981,7 +981,7 @@ where | |||
981 | let ptr = AstPtr::new(self_param); | 981 | let ptr = AstPtr::new(self_param); |
982 | let param_pat = self.alloc_pat( | 982 | let param_pat = self.alloc_pat( |
983 | Pat::Bind { | 983 | Pat::Bind { |
984 | name: Name::self_param(), | 984 | name: SELF_PARAM, |
985 | mode: BindingAnnotation::Unannotated, | 985 | mode: BindingAnnotation::Unannotated, |
986 | subpat: None, | 986 | subpat: None, |
987 | }, | 987 | }, |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 521e47090..07a59193f 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -9,6 +9,7 @@ use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, Ty | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 11 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | name::SELF_TYPE, | ||
12 | path::Path, | 13 | path::Path, |
13 | type_ref::TypeRef, | 14 | type_ref::TypeRef, |
14 | AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, | 15 | AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, |
@@ -81,11 +82,7 @@ impl GenericParams { | |||
81 | GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), | 82 | GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), |
82 | GenericDef::Trait(it) => { | 83 | GenericDef::Trait(it) => { |
83 | // traits get the Self type as an implicit first type parameter | 84 | // traits get the Self type as an implicit first type parameter |
84 | generics.params.push(GenericParam { | 85 | generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); |
85 | idx: start, | ||
86 | name: Name::self_type(), | ||
87 | default: None, | ||
88 | }); | ||
89 | generics.fill(&*it.source(db).ast, start + 1); | 86 | generics.fill(&*it.source(db).ast, start + 1); |
90 | } | 87 | } |
91 | GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start), | 88 | GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start), |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index ec0676783..56831ba05 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -49,7 +49,7 @@ mod marks; | |||
49 | use crate::{ | 49 | use crate::{ |
50 | db::{AstDatabase, DefDatabase, HirDatabase, InternDatabase}, | 50 | db::{AstDatabase, DefDatabase, HirDatabase, InternDatabase}, |
51 | ids::MacroFileKind, | 51 | ids::MacroFileKind, |
52 | name::{AsName, KnownName}, | 52 | name::AsName, |
53 | resolve::Resolver, | 53 | resolve::Resolver, |
54 | source_id::{AstId, FileAstId}, | 54 | source_id::{AstId, FileAstId}, |
55 | }; | 55 | }; |
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index b71590560..5f64b7759 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs | |||
@@ -26,7 +26,7 @@ impl Name { | |||
26 | /// Note: this is private to make creating name from random string hard. | 26 | /// Note: this is private to make creating name from random string hard. |
27 | /// Hopefully, this should allow us to integrate hygiene cleaner in the | 27 | /// Hopefully, this should allow us to integrate hygiene cleaner in the |
28 | /// future, and to switch to interned representation of names. | 28 | /// future, and to switch to interned representation of names. |
29 | fn new(text: SmolStr) -> Name { | 29 | const fn new(text: SmolStr) -> Name { |
30 | Name { text } | 30 | Name { text } |
31 | } | 31 | } |
32 | 32 | ||
@@ -34,14 +34,6 @@ impl Name { | |||
34 | Name::new("[missing name]".into()) | 34 | Name::new("[missing name]".into()) |
35 | } | 35 | } |
36 | 36 | ||
37 | pub(crate) fn self_param() -> Name { | ||
38 | Name::new("self".into()) | ||
39 | } | ||
40 | |||
41 | pub(crate) fn self_type() -> Name { | ||
42 | Name::new("Self".into()) | ||
43 | } | ||
44 | |||
45 | pub(crate) fn tuple_field_name(idx: usize) -> Name { | 37 | pub(crate) fn tuple_field_name(idx: usize) -> Name { |
46 | Name::new(idx.to_string().into()) | 38 | Name::new(idx.to_string().into()) |
47 | } | 39 | } |
@@ -63,38 +55,6 @@ impl Name { | |||
63 | pub fn as_smolstr(&self) -> &SmolStr { | 55 | pub fn as_smolstr(&self) -> &SmolStr { |
64 | &self.text | 56 | &self.text |
65 | } | 57 | } |
66 | |||
67 | pub(crate) fn as_known_name(&self) -> Option<KnownName> { | ||
68 | let name = match self.text.as_str() { | ||
69 | "isize" => KnownName::Isize, | ||
70 | "i8" => KnownName::I8, | ||
71 | "i16" => KnownName::I16, | ||
72 | "i32" => KnownName::I32, | ||
73 | "i64" => KnownName::I64, | ||
74 | "i128" => KnownName::I128, | ||
75 | "usize" => KnownName::Usize, | ||
76 | "u8" => KnownName::U8, | ||
77 | "u16" => KnownName::U16, | ||
78 | "u32" => KnownName::U32, | ||
79 | "u64" => KnownName::U64, | ||
80 | "u128" => KnownName::U128, | ||
81 | "f32" => KnownName::F32, | ||
82 | "f64" => KnownName::F64, | ||
83 | "bool" => KnownName::Bool, | ||
84 | "char" => KnownName::Char, | ||
85 | "str" => KnownName::Str, | ||
86 | "Self" => KnownName::SelfType, | ||
87 | "self" => KnownName::SelfParam, | ||
88 | "macro_rules" => KnownName::MacroRules, | ||
89 | |||
90 | "std" => KnownName::Std, | ||
91 | "iter" => KnownName::Iter, | ||
92 | "IntoIterator" => KnownName::IntoIterator, | ||
93 | "Item" => KnownName::Item, | ||
94 | _ => return None, | ||
95 | }; | ||
96 | Some(name) | ||
97 | } | ||
98 | } | 58 | } |
99 | 59 | ||
100 | pub(crate) trait AsName { | 60 | pub(crate) trait AsName { |
@@ -130,76 +90,31 @@ impl AsName for ra_db::Dependency { | |||
130 | } | 90 | } |
131 | } | 91 | } |
132 | 92 | ||
133 | // Ideally, should be replaced with | 93 | pub(crate) const ISIZE: Name = Name::new(SmolStr::new_inline_from_ascii(5, b"isize")); |
134 | // ``` | 94 | pub(crate) const I8: Name = Name::new(SmolStr::new_inline_from_ascii(2, b"i8")); |
135 | // const ISIZE: Name = Name::new("isize") | 95 | pub(crate) const I16: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i16")); |
136 | // ``` | 96 | pub(crate) const I32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i32")); |
137 | // but const-fn is not that powerful yet. | 97 | pub(crate) const I64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i64")); |
138 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 98 | pub(crate) const I128: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"i128")); |
139 | pub(crate) enum KnownName { | 99 | pub(crate) const USIZE: Name = Name::new(SmolStr::new_inline_from_ascii(5, b"usize")); |
140 | Isize, | 100 | pub(crate) const U8: Name = Name::new(SmolStr::new_inline_from_ascii(2, b"u8")); |
141 | I8, | 101 | pub(crate) const U16: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u16")); |
142 | I16, | 102 | pub(crate) const U32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u32")); |
143 | I32, | 103 | pub(crate) const U64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u64")); |
144 | I64, | 104 | pub(crate) const U128: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"u128")); |
145 | I128, | 105 | pub(crate) const F32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"f32")); |
146 | 106 | pub(crate) const F64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"f64")); | |
147 | Usize, | 107 | pub(crate) const BOOL: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"bool")); |
148 | U8, | 108 | pub(crate) const CHAR: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"char")); |
149 | U16, | 109 | pub(crate) const STR: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"str")); |
150 | U32, | 110 | pub(crate) const SELF_PARAM: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"self")); |
151 | U64, | 111 | pub(crate) const SELF_TYPE: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"Self")); |
152 | U128, | 112 | pub(crate) const MACRO_RULES: Name = Name::new(SmolStr::new_inline_from_ascii(11, b"macro_rules")); |
153 | 113 | pub(crate) const STD: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"std")); | |
154 | F32, | 114 | pub(crate) const ITER: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"iter")); |
155 | F64, | 115 | pub(crate) const INTO_ITERATOR: Name = |
156 | 116 | Name::new(SmolStr::new_inline_from_ascii(12, b"IntoIterator")); | |
157 | Bool, | 117 | pub(crate) const ITEM: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"Item")); |
158 | Char, | ||
159 | Str, | ||
160 | |||
161 | SelfType, | ||
162 | SelfParam, | ||
163 | |||
164 | MacroRules, | ||
165 | |||
166 | Std, | ||
167 | Iter, | ||
168 | IntoIterator, | ||
169 | Item, | ||
170 | } | ||
171 | |||
172 | impl AsName for KnownName { | ||
173 | fn as_name(&self) -> Name { | ||
174 | let s = match self { | ||
175 | KnownName::Isize => "isize", | ||
176 | KnownName::I8 => "i8", | ||
177 | KnownName::I16 => "i16", | ||
178 | KnownName::I32 => "i32", | ||
179 | KnownName::I64 => "i64", | ||
180 | KnownName::I128 => "i128", | ||
181 | KnownName::Usize => "usize", | ||
182 | KnownName::U8 => "u8", | ||
183 | KnownName::U16 => "u16", | ||
184 | KnownName::U32 => "u32", | ||
185 | KnownName::U64 => "u64", | ||
186 | KnownName::U128 => "u128", | ||
187 | KnownName::F32 => "f32", | ||
188 | KnownName::F64 => "f64", | ||
189 | KnownName::Bool => "bool", | ||
190 | KnownName::Char => "char", | ||
191 | KnownName::Str => "str", | ||
192 | KnownName::SelfType => "Self", | ||
193 | KnownName::SelfParam => "self", | ||
194 | KnownName::MacroRules => "macro_rules", | ||
195 | KnownName::Std => "std", | ||
196 | KnownName::Iter => "iter", | ||
197 | KnownName::IntoIterator => "IntoIterator", | ||
198 | KnownName::Item => "Item", | ||
199 | }; | ||
200 | Name::new(s.into()) | ||
201 | } | ||
202 | } | ||
203 | 118 | ||
204 | fn resolve_name(text: &SmolStr) -> SmolStr { | 119 | fn resolve_name(text: &SmolStr) -> SmolStr { |
205 | let raw_start = "r#"; | 120 | let raw_start = "r#"; |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index c84d2eada..bbdc606cd 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -65,8 +65,8 @@ use test_utils::tested_by; | |||
65 | 65 | ||
66 | use crate::{ | 66 | use crate::{ |
67 | diagnostics::DiagnosticSink, either::Either, ids::MacroDefId, | 67 | diagnostics::DiagnosticSink, either::Either, ids::MacroDefId, |
68 | nameres::diagnostics::DefDiagnostic, AsName, AstDatabase, AstId, BuiltinType, Crate, | 68 | nameres::diagnostics::DefDiagnostic, AstDatabase, AstId, BuiltinType, Crate, DefDatabase, |
69 | DefDatabase, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, | 69 | HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, |
70 | }; | 70 | }; |
71 | 71 | ||
72 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; | 72 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; |
@@ -138,8 +138,8 @@ pub struct ModuleScope { | |||
138 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { | 138 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { |
139 | BuiltinType::ALL | 139 | BuiltinType::ALL |
140 | .iter() | 140 | .iter() |
141 | .map(|&(known_name, ty)| { | 141 | .map(|(name, ty)| { |
142 | (known_name.as_name(), Resolution { def: PerNs::types(ty.into()), import: None }) | 142 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None }) |
143 | }) | 143 | }) |
144 | .collect() | 144 | .collect() |
145 | }); | 145 | }); |
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 9f197bb58..552a1b6d9 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -8,12 +8,13 @@ use test_utils::tested_by; | |||
8 | use crate::{ | 8 | use crate::{ |
9 | either::Either, | 9 | either::Either, |
10 | ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, | 10 | ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, |
11 | name::MACRO_RULES, | ||
11 | nameres::{ | 12 | nameres::{ |
12 | diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, | 13 | diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, |
13 | ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, | 14 | ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, |
14 | }, | 15 | }, |
15 | AstId, Const, DefDatabase, Enum, Function, HirFileId, KnownName, MacroDef, Module, Name, Path, | 16 | AstId, Const, DefDatabase, Enum, Function, HirFileId, MacroDef, Module, Name, Path, Static, |
16 | Static, Struct, Trait, TypeAlias, Union, | 17 | Struct, Trait, TypeAlias, Union, |
17 | }; | 18 | }; |
18 | 19 | ||
19 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 20 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -624,7 +625,7 @@ where | |||
624 | } | 625 | } |
625 | 626 | ||
626 | fn is_macro_rules(path: &Path) -> bool { | 627 | fn is_macro_rules(path: &Path) -> bool { |
627 | path.as_ident().and_then(Name::as_known_name) == Some(KnownName::MacroRules) | 628 | path.as_ident() == Some(&MACRO_RULES) |
628 | } | 629 | } |
629 | 630 | ||
630 | fn resolve_submodule( | 631 | fn resolve_submodule( |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index e2a7639b0..ef75308f6 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -13,7 +13,7 @@ use crate::{ | |||
13 | }, | 13 | }, |
14 | generics::GenericParams, | 14 | generics::GenericParams, |
15 | impl_block::ImplBlock, | 15 | impl_block::ImplBlock, |
16 | name::{KnownName, Name}, | 16 | name::{Name, SELF_PARAM, SELF_TYPE}, |
17 | nameres::{CrateDefMap, CrateModuleId, PerNs}, | 17 | nameres::{CrateDefMap, CrateModuleId, PerNs}, |
18 | path::Path, | 18 | path::Path, |
19 | MacroDef, ModuleDef, Trait, | 19 | MacroDef, ModuleDef, Trait, |
@@ -151,7 +151,7 @@ impl Resolver { | |||
151 | if let Some(name) = path.as_ident() { | 151 | if let Some(name) = path.as_ident() { |
152 | PathResult::from_resolution(self.resolve_name(db, name)) | 152 | PathResult::from_resolution(self.resolve_name(db, name)) |
153 | } else if path.is_self() { | 153 | } else if path.is_self() { |
154 | PathResult::from_resolution(self.resolve_name(db, &Name::self_param())) | 154 | PathResult::from_resolution(self.resolve_name(db, &SELF_PARAM)) |
155 | } else { | 155 | } else { |
156 | let (item_map, module) = match self.module() { | 156 | let (item_map, module) = match self.module() { |
157 | Some(it) => it, | 157 | Some(it) => it, |
@@ -270,7 +270,7 @@ impl Scope { | |||
270 | fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> { | 270 | fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> { |
271 | match self { | 271 | match self { |
272 | Scope::ModuleScope(m) => { | 272 | Scope::ModuleScope(m) => { |
273 | if let Some(KnownName::SelfParam) = name.as_known_name() { | 273 | if name == &SELF_PARAM { |
274 | PerNs::types(Resolution::Def(m.crate_def_map.mk_module(m.module_id).into())) | 274 | PerNs::types(Resolution::Def(m.crate_def_map.mk_module(m.module_id).into())) |
275 | } else { | 275 | } else { |
276 | m.crate_def_map | 276 | m.crate_def_map |
@@ -283,7 +283,7 @@ impl Scope { | |||
283 | None => PerNs::none(), | 283 | None => PerNs::none(), |
284 | }, | 284 | }, |
285 | Scope::ImplBlockScope(i) => { | 285 | Scope::ImplBlockScope(i) => { |
286 | if name.as_known_name() == Some(KnownName::SelfType) { | 286 | if name == &SELF_TYPE { |
287 | PerNs::types(Resolution::SelfType(*i)) | 287 | PerNs::types(Resolution::SelfType(*i)) |
288 | } else { | 288 | } else { |
289 | PerNs::none() | 289 | PerNs::none() |
@@ -329,7 +329,7 @@ impl Scope { | |||
329 | } | 329 | } |
330 | } | 330 | } |
331 | Scope::ImplBlockScope(i) => { | 331 | Scope::ImplBlockScope(i) => { |
332 | f(Name::self_type(), PerNs::types(Resolution::SelfType(*i))); | 332 | f(SELF_TYPE, PerNs::types(Resolution::SelfType(*i))); |
333 | } | 333 | } |
334 | Scope::ExprScope(e) => { | 334 | Scope::ExprScope(e) => { |
335 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { | 335 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 973de70df..52a49070a 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -40,6 +40,7 @@ use crate::{ | |||
40 | PatId, Statement, UnaryOp, | 40 | PatId, Statement, UnaryOp, |
41 | }, | 41 | }, |
42 | generics::{GenericParams, HasGenericParams}, | 42 | generics::{GenericParams, HasGenericParams}, |
43 | name::{INTO_ITERATOR, ITEM, ITER, SELF_TYPE, STD}, | ||
43 | nameres::{Namespace, PerNs}, | 44 | nameres::{Namespace, PerNs}, |
44 | path::{GenericArg, GenericArgs, PathKind, PathSegment}, | 45 | path::{GenericArg, GenericArgs, PathKind, PathSegment}, |
45 | resolve::{ | 46 | resolve::{ |
@@ -48,8 +49,8 @@ use crate::{ | |||
48 | }, | 49 | }, |
49 | ty::infer::diagnostics::InferenceDiagnostic, | 50 | ty::infer::diagnostics::InferenceDiagnostic, |
50 | type_ref::{Mutability, TypeRef}, | 51 | type_ref::{Mutability, TypeRef}, |
51 | AdtDef, AsName, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, KnownName, | 52 | AdtDef, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, ModuleDef, Name, Path, |
52 | ModuleDef, Name, Path, StructField, | 53 | StructField, |
53 | }; | 54 | }; |
54 | 55 | ||
55 | mod unify; | 56 | mod unify; |
@@ -842,7 +843,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
842 | // Parent arguments are unknown, except for the receiver type | 843 | // Parent arguments are unknown, except for the receiver type |
843 | if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) { | 844 | if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) { |
844 | for param in &parent_generics.params { | 845 | for param in &parent_generics.params { |
845 | if param.name.as_known_name() == Some(crate::KnownName::SelfType) { | 846 | if param.name == SELF_TYPE { |
846 | substs.push(receiver_ty.clone()); | 847 | substs.push(receiver_ty.clone()); |
847 | } else { | 848 | } else { |
848 | substs.push(Ty::Unknown); | 849 | substs.push(Ty::Unknown); |
@@ -1346,15 +1347,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1346 | let into_iter_path = Path { | 1347 | let into_iter_path = Path { |
1347 | kind: PathKind::Abs, | 1348 | kind: PathKind::Abs, |
1348 | segments: vec![ | 1349 | segments: vec![ |
1349 | PathSegment { name: KnownName::Std.as_name(), args_and_bindings: None }, | 1350 | PathSegment { name: STD, args_and_bindings: None }, |
1350 | PathSegment { name: KnownName::Iter.as_name(), args_and_bindings: None }, | 1351 | PathSegment { name: ITER, args_and_bindings: None }, |
1351 | PathSegment { name: KnownName::IntoIterator.as_name(), args_and_bindings: None }, | 1352 | PathSegment { name: INTO_ITERATOR, args_and_bindings: None }, |
1352 | ], | 1353 | ], |
1353 | }; | 1354 | }; |
1354 | 1355 | ||
1355 | match self.resolver.resolve_path_segments(self.db, &into_iter_path).into_fully_resolved() { | 1356 | match self.resolver.resolve_path_segments(self.db, &into_iter_path).into_fully_resolved() { |
1356 | PerNs { types: Some(Def(Trait(trait_))), .. } => { | 1357 | PerNs { types: Some(Def(Trait(trait_))), .. } => { |
1357 | Some(trait_.associated_type_by_name(self.db, KnownName::Item.as_name())?) | 1358 | Some(trait_.associated_type_by_name(self.db, ITEM)?) |
1358 | } | 1359 | } |
1359 | _ => None, | 1360 | _ => None, |
1360 | } | 1361 | } |