diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/builtin_type.rs | 42 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 45 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_derive.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/name.rs | 166 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/autoderef.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/builtin.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/utils.rs | 6 |
16 files changed, 192 insertions, 173 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index c705d1630..d1153fa62 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -17,7 +17,7 @@ use hir_def::{ | |||
17 | }; | 17 | }; |
18 | use hir_expand::{ | 18 | use hir_expand::{ |
19 | diagnostics::DiagnosticSink, | 19 | diagnostics::DiagnosticSink, |
20 | name::{self, AsName}, | 20 | name::{AsName, N}, |
21 | MacroDefId, | 21 | MacroDefId, |
22 | }; | 22 | }; |
23 | use hir_ty::{ | 23 | use hir_ty::{ |
@@ -723,7 +723,7 @@ impl Local { | |||
723 | } | 723 | } |
724 | 724 | ||
725 | pub fn is_self(self, db: &impl HirDatabase) -> bool { | 725 | pub fn is_self(self, db: &impl HirDatabase) -> bool { |
726 | self.name(db) == Some(name::SELF_PARAM) | 726 | self.name(db) == Some(N![self]) |
727 | } | 727 | } |
728 | 728 | ||
729 | pub fn is_mut(self, db: &impl HirDatabase) -> bool { | 729 | pub fn is_mut(self, db: &impl HirDatabase) -> bool { |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index cc068ff94..6c760166f 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | //! representation. | 2 | //! representation. |
3 | 3 | ||
4 | use either::Either; | 4 | use either::Either; |
5 | use hir_expand::name::{self, AsName, Name}; | 5 | use hir_expand::name::{AsName, Name, N}; |
6 | use ra_arena::Arena; | 6 | use ra_arena::Arena; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | ast::{ | 8 | ast::{ |
@@ -68,7 +68,7 @@ where | |||
68 | let ptr = AstPtr::new(&self_param); | 68 | let ptr = AstPtr::new(&self_param); |
69 | let param_pat = self.alloc_pat( | 69 | let param_pat = self.alloc_pat( |
70 | Pat::Bind { | 70 | Pat::Bind { |
71 | name: name::SELF_PARAM, | 71 | name: N![self], |
72 | mode: BindingAnnotation::Unannotated, | 72 | mode: BindingAnnotation::Unannotated, |
73 | subpat: None, | 73 | subpat: None, |
74 | }, | 74 | }, |
diff --git a/crates/ra_hir_def/src/builtin_type.rs b/crates/ra_hir_def/src/builtin_type.rs index 5e8157144..757123f82 100644 --- a/crates/ra_hir_def/src/builtin_type.rs +++ b/crates/ra_hir_def/src/builtin_type.rs | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | use std::fmt; | 6 | use std::fmt; |
7 | 7 | ||
8 | use hir_expand::name::{self, Name}; | 8 | use hir_expand::name::{Name, N}; |
9 | 9 | ||
10 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | 10 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] |
11 | pub enum Signedness { | 11 | pub enum Signedness { |
@@ -52,26 +52,26 @@ pub enum BuiltinType { | |||
52 | impl BuiltinType { | 52 | impl BuiltinType { |
53 | #[rustfmt::skip] | 53 | #[rustfmt::skip] |
54 | pub const ALL: &'static [(Name, BuiltinType)] = &[ | 54 | pub const ALL: &'static [(Name, BuiltinType)] = &[ |
55 | (name::CHAR, BuiltinType::Char), | 55 | (N![char], BuiltinType::Char), |
56 | (name::BOOL, BuiltinType::Bool), | 56 | (N![bool], BuiltinType::Bool), |
57 | (name::STR, BuiltinType::Str ), | 57 | (N![str], BuiltinType::Str), |
58 | 58 | ||
59 | (name::ISIZE, BuiltinType::Int(BuiltinInt::ISIZE)), | 59 | (N![isize], BuiltinType::Int(BuiltinInt::ISIZE)), |
60 | (name::I8, BuiltinType::Int(BuiltinInt::I8)), | 60 | (N![i8], BuiltinType::Int(BuiltinInt::I8)), |
61 | (name::I16, BuiltinType::Int(BuiltinInt::I16)), | 61 | (N![i16], BuiltinType::Int(BuiltinInt::I16)), |
62 | (name::I32, BuiltinType::Int(BuiltinInt::I32)), | 62 | (N![i32], BuiltinType::Int(BuiltinInt::I32)), |
63 | (name::I64, BuiltinType::Int(BuiltinInt::I64)), | 63 | (N![i64], BuiltinType::Int(BuiltinInt::I64)), |
64 | (name::I128, BuiltinType::Int(BuiltinInt::I128)), | 64 | (N![i128], BuiltinType::Int(BuiltinInt::I128)), |
65 | 65 | ||
66 | (name::USIZE, BuiltinType::Int(BuiltinInt::USIZE)), | 66 | (N![usize], BuiltinType::Int(BuiltinInt::USIZE)), |
67 | (name::U8, BuiltinType::Int(BuiltinInt::U8)), | 67 | (N![u8], BuiltinType::Int(BuiltinInt::U8)), |
68 | (name::U16, BuiltinType::Int(BuiltinInt::U16)), | 68 | (N![u16], BuiltinType::Int(BuiltinInt::U16)), |
69 | (name::U32, BuiltinType::Int(BuiltinInt::U32)), | 69 | (N![u32], BuiltinType::Int(BuiltinInt::U32)), |
70 | (name::U64, BuiltinType::Int(BuiltinInt::U64)), | 70 | (N![u64], BuiltinType::Int(BuiltinInt::U64)), |
71 | (name::U128, BuiltinType::Int(BuiltinInt::U128)), | 71 | (N![u128], BuiltinType::Int(BuiltinInt::U128)), |
72 | 72 | ||
73 | (name::F32, BuiltinType::Float(BuiltinFloat::F32)), | 73 | (N![f32], BuiltinType::Float(BuiltinFloat::F32)), |
74 | (name::F64, BuiltinType::Float(BuiltinFloat::F64)), | 74 | (N![f64], BuiltinType::Float(BuiltinFloat::F64)), |
75 | ]; | 75 | ]; |
76 | } | 76 | } |
77 | 77 | ||
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index b2dac183e..afeac0ec2 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_expand::{ | 5 | use hir_expand::{ |
6 | name::{self, AsName, Name}, | 6 | name::{AsName, Name, N}, |
7 | AstId, | 7 | AstId, |
8 | }; | 8 | }; |
9 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 9 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
@@ -37,7 +37,7 @@ impl FunctionData { | |||
37 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | 37 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { |
38 | TypeRef::from_ast(type_ref) | 38 | TypeRef::from_ast(type_ref) |
39 | } else { | 39 | } else { |
40 | let self_type = TypeRef::Path(name::SELF_TYPE.into()); | 40 | let self_type = TypeRef::Path(N![Self].into()); |
41 | match self_param.kind() { | 41 | match self_param.kind() { |
42 | ast::SelfParamKind::Owned => self_type, | 42 | ast::SelfParamKind::Owned => self_type, |
43 | ast::SelfParamKind::Ref => { | 43 | ast::SelfParamKind::Ref => { |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index e502dd798..2b13748f3 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -6,7 +6,7 @@ use std::sync::Arc; | |||
6 | 6 | ||
7 | use either::Either; | 7 | use either::Either; |
8 | use hir_expand::{ | 8 | use hir_expand::{ |
9 | name::{self, AsName, Name}, | 9 | name::{AsName, Name, N}, |
10 | InFile, | 10 | InFile, |
11 | }; | 11 | }; |
12 | use ra_arena::{map::ArenaMap, Arena}; | 12 | use ra_arena::{map::ArenaMap, Arena}; |
@@ -90,11 +90,11 @@ impl GenericParams { | |||
90 | 90 | ||
91 | // traits get the Self type as an implicit first type parameter | 91 | // traits get the Self type as an implicit first type parameter |
92 | let self_param_id = | 92 | let self_param_id = |
93 | generics.types.alloc(TypeParamData { name: name::SELF_TYPE, default: None }); | 93 | generics.types.alloc(TypeParamData { name: N![Self], default: None }); |
94 | sm.insert(self_param_id, Either::Left(src.value.clone())); | 94 | sm.insert(self_param_id, Either::Left(src.value.clone())); |
95 | // add super traits as bounds on Self | 95 | // add super traits as bounds on Self |
96 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar | 96 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar |
97 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); | 97 | let self_param = TypeRef::Path(N![Self].into()); |
98 | generics.fill_bounds(&src.value, self_param); | 98 | generics.fill_bounds(&src.value, self_param); |
99 | 99 | ||
100 | generics.fill(&mut sm, &src.value); | 100 | generics.fill(&mut sm, &src.value); |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 04aadead1..e81bac914 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | use hir_expand::{ | 6 | use hir_expand::{ |
7 | builtin_derive::find_builtin_derive, | 7 | builtin_derive::find_builtin_derive, |
8 | builtin_macro::find_builtin_macro, | 8 | builtin_macro::find_builtin_macro, |
9 | name::{self, AsName, Name}, | 9 | name::{AsName, Name, N}, |
10 | HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, | 10 | HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, |
11 | }; | 11 | }; |
12 | use ra_cfg::CfgOptions; | 12 | use ra_cfg::CfgOptions; |
@@ -918,7 +918,7 @@ where | |||
918 | } | 918 | } |
919 | 919 | ||
920 | fn is_macro_rules(path: &Path) -> bool { | 920 | fn is_macro_rules(path: &Path) -> bool { |
921 | path.as_ident() == Some(&name::MACRO_RULES) | 921 | path.as_ident() == Some(&N![macro_rules]) |
922 | } | 922 | } |
923 | 923 | ||
924 | #[cfg(test)] | 924 | #[cfg(test)] |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 50f0cad94..36ad27867 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -6,7 +6,7 @@ use std::{iter, sync::Arc}; | |||
6 | use either::Either; | 6 | use either::Either; |
7 | use hir_expand::{ | 7 | use hir_expand::{ |
8 | hygiene::Hygiene, | 8 | hygiene::Hygiene, |
9 | name::{self, AsName, Name}, | 9 | name::{AsName, Name, N}, |
10 | }; | 10 | }; |
11 | use ra_db::CrateId; | 11 | use ra_db::CrateId; |
12 | use ra_syntax::{ | 12 | use ra_syntax::{ |
@@ -276,7 +276,7 @@ impl GenericArgs { | |||
276 | } | 276 | } |
277 | if let Some(ret_type) = ret_type { | 277 | if let Some(ret_type) = ret_type { |
278 | let type_ref = TypeRef::from_ast_opt(ret_type.type_ref()); | 278 | let type_ref = TypeRef::from_ast_opt(ret_type.type_ref()); |
279 | bindings.push((name::OUTPUT_TYPE, type_ref)) | 279 | bindings.push((N![Output], type_ref)) |
280 | } | 280 | } |
281 | if args.is_empty() && bindings.is_empty() { | 281 | if args.is_empty() && bindings.is_empty() { |
282 | None | 282 | None |
@@ -297,68 +297,63 @@ impl From<Name> for Path { | |||
297 | } | 297 | } |
298 | 298 | ||
299 | pub mod known { | 299 | pub mod known { |
300 | use hir_expand::name; | 300 | use hir_expand::name::N; |
301 | 301 | ||
302 | use super::{Path, PathKind}; | 302 | use super::{Path, PathKind}; |
303 | 303 | ||
304 | macro_rules! P { | ||
305 | ($start:ident $(:: $seg:ident)*) => { Path::from_simple_segments(PathKind::Abs, vec![N![$start], $(N![$seg],)*]) }; | ||
306 | } | ||
307 | |||
304 | pub fn std_iter_into_iterator() -> Path { | 308 | pub fn std_iter_into_iterator() -> Path { |
305 | Path::from_simple_segments( | 309 | P![std::iter::IntoIterator] |
306 | PathKind::Abs, | ||
307 | vec![name::STD, name::ITER, name::INTO_ITERATOR_TYPE], | ||
308 | ) | ||
309 | } | 310 | } |
310 | 311 | ||
311 | pub fn std_ops_try() -> Path { | 312 | pub fn std_ops_try() -> Path { |
312 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::TRY_TYPE]) | 313 | P![std::ops::Try] |
313 | } | 314 | } |
314 | 315 | ||
315 | pub fn std_ops_range() -> Path { | 316 | pub fn std_ops_range() -> Path { |
316 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_TYPE]) | 317 | P![std::ops::Range] |
317 | } | 318 | } |
318 | 319 | ||
319 | pub fn std_ops_range_from() -> Path { | 320 | pub fn std_ops_range_from() -> Path { |
320 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_FROM_TYPE]) | 321 | P![std::ops::RangeFrom] |
321 | } | 322 | } |
322 | 323 | ||
323 | pub fn std_ops_range_full() -> Path { | 324 | pub fn std_ops_range_full() -> Path { |
324 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_FULL_TYPE]) | 325 | P![std::ops::RangeFull] |
325 | } | 326 | } |
326 | 327 | ||
327 | pub fn std_ops_range_inclusive() -> Path { | 328 | pub fn std_ops_range_inclusive() -> Path { |
328 | Path::from_simple_segments( | 329 | P![std::ops::RangeInclusive] |
329 | PathKind::Abs, | ||
330 | vec![name::STD, name::OPS, name::RANGE_INCLUSIVE_TYPE], | ||
331 | ) | ||
332 | } | 330 | } |
333 | 331 | ||
334 | pub fn std_ops_range_to() -> Path { | 332 | pub fn std_ops_range_to() -> Path { |
335 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_TO_TYPE]) | 333 | P![std::ops::RangeTo] |
336 | } | 334 | } |
337 | 335 | ||
338 | pub fn std_ops_range_to_inclusive() -> Path { | 336 | pub fn std_ops_range_to_inclusive() -> Path { |
339 | Path::from_simple_segments( | 337 | P![std::ops::RangeToInclusive] |
340 | PathKind::Abs, | ||
341 | vec![name::STD, name::OPS, name::RANGE_TO_INCLUSIVE_TYPE], | ||
342 | ) | ||
343 | } | 338 | } |
344 | 339 | ||
345 | pub fn std_ops_neg() -> Path { | 340 | pub fn std_ops_neg() -> Path { |
346 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::NEG_TYPE]) | 341 | P![std::ops::Neg] |
347 | } | 342 | } |
348 | 343 | ||
349 | pub fn std_ops_not() -> Path { | 344 | pub fn std_ops_not() -> Path { |
350 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::NOT_TYPE]) | 345 | P![std::ops::Not] |
351 | } | 346 | } |
352 | 347 | ||
353 | pub fn std_result_result() -> Path { | 348 | pub fn std_result_result() -> Path { |
354 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::RESULT, name::RESULT_TYPE]) | 349 | P![std::result::Result] |
355 | } | 350 | } |
356 | 351 | ||
357 | pub fn std_future_future() -> Path { | 352 | pub fn std_future_future() -> Path { |
358 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::FUTURE, name::FUTURE_TYPE]) | 353 | P![std::future::Future] |
359 | } | 354 | } |
360 | 355 | ||
361 | pub fn std_boxed_box() -> Path { | 356 | pub fn std_boxed_box() -> Path { |
362 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::BOXED, name::BOX_TYPE]) | 357 | P![std::boxed::Box] |
363 | } | 358 | } |
364 | } | 359 | } |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 17b2169d2..0fb529527 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_expand::{ | 4 | use hir_expand::{ |
5 | name::{self, Name}, | 5 | name::{Name, N}, |
6 | MacroDefId, | 6 | MacroDefId, |
7 | }; | 7 | }; |
8 | use ra_db::CrateId; | 8 | use ra_db::CrateId; |
@@ -163,13 +163,13 @@ impl Resolver { | |||
163 | } | 163 | } |
164 | } | 164 | } |
165 | Scope::ImplBlockScope(impl_) => { | 165 | Scope::ImplBlockScope(impl_) => { |
166 | if first_name == &name::SELF_TYPE { | 166 | if first_name == &N![Self] { |
167 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 167 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
168 | return Some((TypeNs::SelfType(*impl_), idx)); | 168 | return Some((TypeNs::SelfType(*impl_), idx)); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | Scope::AdtScope(adt) => { | 171 | Scope::AdtScope(adt) => { |
172 | if first_name == &name::SELF_TYPE { | 172 | if first_name == &N![Self] { |
173 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 173 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
174 | return Some((TypeNs::AdtSelfType(*adt), idx)); | 174 | return Some((TypeNs::AdtSelfType(*adt), idx)); |
175 | } | 175 | } |
@@ -223,7 +223,7 @@ impl Resolver { | |||
223 | return None; | 223 | return None; |
224 | } | 224 | } |
225 | let n_segments = path.segments.len(); | 225 | let n_segments = path.segments.len(); |
226 | let tmp = name::SELF_PARAM; | 226 | let tmp = N![self]; |
227 | let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; | 227 | let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; |
228 | let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); | 228 | let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); |
229 | for scope in self.scopes.iter().rev() { | 229 | for scope in self.scopes.iter().rev() { |
@@ -259,13 +259,13 @@ impl Resolver { | |||
259 | Scope::GenericParams { .. } => continue, | 259 | Scope::GenericParams { .. } => continue, |
260 | 260 | ||
261 | Scope::ImplBlockScope(impl_) if n_segments > 1 => { | 261 | Scope::ImplBlockScope(impl_) if n_segments > 1 => { |
262 | if first_name == &name::SELF_TYPE { | 262 | if first_name == &N![Self] { |
263 | let ty = TypeNs::SelfType(*impl_); | 263 | let ty = TypeNs::SelfType(*impl_); |
264 | return Some(ResolveValueResult::Partial(ty, 1)); | 264 | return Some(ResolveValueResult::Partial(ty, 1)); |
265 | } | 265 | } |
266 | } | 266 | } |
267 | Scope::AdtScope(adt) if n_segments > 1 => { | 267 | Scope::AdtScope(adt) if n_segments > 1 => { |
268 | if first_name == &name::SELF_TYPE { | 268 | if first_name == &N![Self] { |
269 | let ty = TypeNs::AdtSelfType(*adt); | 269 | let ty = TypeNs::AdtSelfType(*adt); |
270 | return Some(ResolveValueResult::Partial(ty, 1)); | 270 | return Some(ResolveValueResult::Partial(ty, 1)); |
271 | } | 271 | } |
@@ -439,10 +439,10 @@ impl Scope { | |||
439 | } | 439 | } |
440 | } | 440 | } |
441 | Scope::ImplBlockScope(i) => { | 441 | Scope::ImplBlockScope(i) => { |
442 | f(name::SELF_TYPE, ScopeDef::ImplSelfType((*i).into())); | 442 | f(N![Self], ScopeDef::ImplSelfType((*i).into())); |
443 | } | 443 | } |
444 | Scope::AdtScope(i) => { | 444 | Scope::AdtScope(i) => { |
445 | f(name::SELF_TYPE, ScopeDef::AdtSelfType((*i).into())); | 445 | f(N![Self], ScopeDef::AdtSelfType((*i).into())); |
446 | } | 446 | } |
447 | Scope::ExprScope(scope) => { | 447 | Scope::ExprScope(scope) => { |
448 | scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| { | 448 | scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| { |
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index 574637602..d7f8ada78 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs | |||
@@ -12,10 +12,10 @@ use crate::db::AstDatabase; | |||
12 | use crate::{name, quote, MacroCallId, MacroDefId, MacroDefKind}; | 12 | use crate::{name, quote, MacroCallId, MacroDefId, MacroDefKind}; |
13 | 13 | ||
14 | macro_rules! register_builtin { | 14 | macro_rules! register_builtin { |
15 | ( $(($name:ident, $kind: ident) => $expand:ident),* ) => { | 15 | ( $($trait:ident => $expand:ident),* ) => { |
16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
17 | pub enum BuiltinDeriveExpander { | 17 | pub enum BuiltinDeriveExpander { |
18 | $($kind),* | 18 | $($trait),* |
19 | } | 19 | } |
20 | 20 | ||
21 | impl BuiltinDeriveExpander { | 21 | impl BuiltinDeriveExpander { |
@@ -26,7 +26,7 @@ macro_rules! register_builtin { | |||
26 | tt: &tt::Subtree, | 26 | tt: &tt::Subtree, |
27 | ) -> Result<tt::Subtree, mbe::ExpandError> { | 27 | ) -> Result<tt::Subtree, mbe::ExpandError> { |
28 | let expander = match *self { | 28 | let expander = match *self { |
29 | $( BuiltinDeriveExpander::$kind => $expand, )* | 29 | $( BuiltinDeriveExpander::$trait => $expand, )* |
30 | }; | 30 | }; |
31 | expander(db, id, tt) | 31 | expander(db, id, tt) |
32 | } | 32 | } |
@@ -34,7 +34,7 @@ macro_rules! register_builtin { | |||
34 | 34 | ||
35 | pub fn find_builtin_derive(ident: &name::Name) -> Option<MacroDefId> { | 35 | pub fn find_builtin_derive(ident: &name::Name) -> Option<MacroDefId> { |
36 | let kind = match ident { | 36 | let kind = match ident { |
37 | $( id if id == &name::$name => BuiltinDeriveExpander::$kind, )* | 37 | $( id if id == &name::N![$trait] => BuiltinDeriveExpander::$trait, )* |
38 | _ => return None, | 38 | _ => return None, |
39 | }; | 39 | }; |
40 | 40 | ||
@@ -44,15 +44,15 @@ macro_rules! register_builtin { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | register_builtin! { | 46 | register_builtin! { |
47 | (COPY_TRAIT, Copy) => copy_expand, | 47 | Copy => copy_expand, |
48 | (CLONE_TRAIT, Clone) => clone_expand, | 48 | Clone => clone_expand, |
49 | (DEFAULT_TRAIT, Default) => default_expand, | 49 | Default => default_expand, |
50 | (DEBUG_TRAIT, Debug) => debug_expand, | 50 | Debug => debug_expand, |
51 | (HASH_TRAIT, Hash) => hash_expand, | 51 | Hash => hash_expand, |
52 | (ORD_TRAIT, Ord) => ord_expand, | 52 | Ord => ord_expand, |
53 | (PARTIAL_ORD_TRAIT, PartialOrd) => partial_ord_expand, | 53 | PartialOrd => partial_ord_expand, |
54 | (EQ_TRAIT, Eq) => eq_expand, | 54 | Eq => eq_expand, |
55 | (PARTIAL_EQ_TRAIT, PartialEq) => partial_eq_expand | 55 | PartialEq => partial_eq_expand |
56 | } | 56 | } |
57 | 57 | ||
58 | struct BasicAdtInfo { | 58 | struct BasicAdtInfo { |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index be5f3cbe3..e5046ad4c 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -34,7 +34,7 @@ macro_rules! register_builtin { | |||
34 | ast_id: AstId<ast::MacroCall>, | 34 | ast_id: AstId<ast::MacroCall>, |
35 | ) -> Option<MacroDefId> { | 35 | ) -> Option<MacroDefId> { |
36 | let kind = match ident { | 36 | let kind = match ident { |
37 | $( id if id == &name::$name => BuiltinFnLikeExpander::$kind, )* | 37 | $( id if id == &name::N![$name] => BuiltinFnLikeExpander::$kind, )* |
38 | _ => return None, | 38 | _ => return None, |
39 | }; | 39 | }; |
40 | 40 | ||
@@ -44,15 +44,15 @@ macro_rules! register_builtin { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | register_builtin! { | 46 | register_builtin! { |
47 | (COLUMN_MACRO, Column) => column_expand, | 47 | (column, Column) => column_expand, |
48 | (COMPILE_ERROR_MACRO, CompileError) => compile_error_expand, | 48 | (compile_error, CompileError) => compile_error_expand, |
49 | (FILE_MACRO, File) => file_expand, | 49 | (file, File) => file_expand, |
50 | (LINE_MACRO, Line) => line_expand, | 50 | (line, Line) => line_expand, |
51 | (STRINGIFY_MACRO, Stringify) => stringify_expand, | 51 | (stringify, Stringify) => stringify_expand, |
52 | (FORMAT_ARGS_MACRO, FormatArgs) => format_args_expand, | 52 | (format_args, FormatArgs) => format_args_expand, |
53 | // format_args_nl only differs in that it adds a newline in the end, | 53 | // format_args_nl only differs in that it adds a newline in the end, |
54 | // so we use the same stub expansion for now | 54 | // so we use the same stub expansion for now |
55 | (FORMAT_ARGS_NL_MACRO, FormatArgsNl) => format_args_expand | 55 | (format_args_nl, FormatArgsNl) => format_args_expand |
56 | } | 56 | } |
57 | 57 | ||
58 | fn to_line_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize { | 58 | fn to_line_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize { |
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs index 9e68dd98d..8b3141d75 100644 --- a/crates/ra_hir_expand/src/name.rs +++ b/crates/ra_hir_expand/src/name.rs | |||
@@ -104,73 +104,99 @@ impl AsName for ra_db::Dependency { | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | // Primitives | 107 | pub mod known { |
108 | pub const ISIZE: Name = Name::new_inline_ascii(b"isize"); | 108 | macro_rules! known_names { |
109 | pub const I8: Name = Name::new_inline_ascii(b"i8"); | 109 | ($($ident:ident),* $(,)?) => { |
110 | pub const I16: Name = Name::new_inline_ascii(b"i16"); | 110 | $( |
111 | pub const I32: Name = Name::new_inline_ascii(b"i32"); | 111 | #[allow(bad_style)] |
112 | pub const I64: Name = Name::new_inline_ascii(b"i64"); | 112 | pub const $ident: super::Name = |
113 | pub const I128: Name = Name::new_inline_ascii(b"i128"); | 113 | super::Name::new_inline_ascii(stringify!($ident).as_bytes()); |
114 | pub const USIZE: Name = Name::new_inline_ascii(b"usize"); | 114 | )* |
115 | pub const U8: Name = Name::new_inline_ascii(b"u8"); | 115 | }; |
116 | pub const U16: Name = Name::new_inline_ascii(b"u16"); | 116 | } |
117 | pub const U32: Name = Name::new_inline_ascii(b"u32"); | 117 | |
118 | pub const U64: Name = Name::new_inline_ascii(b"u64"); | 118 | known_names!( |
119 | pub const U128: Name = Name::new_inline_ascii(b"u128"); | 119 | // Primitives |
120 | pub const F32: Name = Name::new_inline_ascii(b"f32"); | 120 | isize, |
121 | pub const F64: Name = Name::new_inline_ascii(b"f64"); | 121 | i8, |
122 | pub const BOOL: Name = Name::new_inline_ascii(b"bool"); | 122 | i16, |
123 | pub const CHAR: Name = Name::new_inline_ascii(b"char"); | 123 | i32, |
124 | pub const STR: Name = Name::new_inline_ascii(b"str"); | 124 | i64, |
125 | 125 | i128, | |
126 | // Special names | 126 | usize, |
127 | pub const SELF_PARAM: Name = Name::new_inline_ascii(b"self"); | 127 | u8, |
128 | pub const SELF_TYPE: Name = Name::new_inline_ascii(b"Self"); | 128 | u16, |
129 | pub const MACRO_RULES: Name = Name::new_inline_ascii(b"macro_rules"); | 129 | u32, |
130 | 130 | u64, | |
131 | // Components of known path (value or mod name) | 131 | u128, |
132 | pub const STD: Name = Name::new_inline_ascii(b"std"); | 132 | f32, |
133 | pub const ITER: Name = Name::new_inline_ascii(b"iter"); | 133 | f64, |
134 | pub const OPS: Name = Name::new_inline_ascii(b"ops"); | 134 | bool, |
135 | pub const FUTURE: Name = Name::new_inline_ascii(b"future"); | 135 | char, |
136 | pub const RESULT: Name = Name::new_inline_ascii(b"result"); | 136 | str, |
137 | pub const BOXED: Name = Name::new_inline_ascii(b"boxed"); | 137 | // Special names |
138 | 138 | macro_rules, | |
139 | // Components of known path (type name) | 139 | // Components of known path (value or mod name) |
140 | pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(b"IntoIterator"); | 140 | std, |
141 | pub const ITEM_TYPE: Name = Name::new_inline_ascii(b"Item"); | 141 | iter, |
142 | pub const TRY_TYPE: Name = Name::new_inline_ascii(b"Try"); | 142 | ops, |
143 | pub const OK_TYPE: Name = Name::new_inline_ascii(b"Ok"); | 143 | future, |
144 | pub const FUTURE_TYPE: Name = Name::new_inline_ascii(b"Future"); | 144 | result, |
145 | pub const RESULT_TYPE: Name = Name::new_inline_ascii(b"Result"); | 145 | boxed, |
146 | pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(b"Output"); | 146 | // Components of known path (type name) |
147 | pub const TARGET_TYPE: Name = Name::new_inline_ascii(b"Target"); | 147 | IntoIterator, |
148 | pub const BOX_TYPE: Name = Name::new_inline_ascii(b"Box"); | 148 | Item, |
149 | pub const RANGE_FROM_TYPE: Name = Name::new_inline_ascii(b"RangeFrom"); | 149 | Try, |
150 | pub const RANGE_FULL_TYPE: Name = Name::new_inline_ascii(b"RangeFull"); | 150 | Ok, |
151 | pub const RANGE_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(b"RangeInclusive"); | 151 | Future, |
152 | pub const RANGE_TO_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(b"RangeToInclusive"); | 152 | Result, |
153 | pub const RANGE_TO_TYPE: Name = Name::new_inline_ascii(b"RangeTo"); | 153 | Output, |
154 | pub const RANGE_TYPE: Name = Name::new_inline_ascii(b"Range"); | 154 | Target, |
155 | pub const NEG_TYPE: Name = Name::new_inline_ascii(b"Neg"); | 155 | Box, |
156 | pub const NOT_TYPE: Name = Name::new_inline_ascii(b"Not"); | 156 | RangeFrom, |
157 | 157 | RangeFull, | |
158 | // Builtin Macros | 158 | RangeInclusive, |
159 | pub const FILE_MACRO: Name = Name::new_inline_ascii(b"file"); | 159 | RangeToInclusive, |
160 | pub const COLUMN_MACRO: Name = Name::new_inline_ascii(b"column"); | 160 | RangeTo, |
161 | pub const COMPILE_ERROR_MACRO: Name = Name::new_inline_ascii(b"compile_error"); | 161 | Range, |
162 | pub const LINE_MACRO: Name = Name::new_inline_ascii(b"line"); | 162 | Neg, |
163 | pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(b"stringify"); | 163 | Not, |
164 | pub const FORMAT_ARGS_MACRO: Name = Name::new_inline_ascii(b"format_args"); | 164 | // Builtin macros |
165 | pub const FORMAT_ARGS_NL_MACRO: Name = Name::new_inline_ascii(b"format_args_nl"); | 165 | file, |
166 | 166 | column, | |
167 | // Builtin derives | 167 | compile_error, |
168 | pub const COPY_TRAIT: Name = Name::new_inline_ascii(b"Copy"); | 168 | line, |
169 | pub const CLONE_TRAIT: Name = Name::new_inline_ascii(b"Clone"); | 169 | stringify, |
170 | pub const DEFAULT_TRAIT: Name = Name::new_inline_ascii(b"Default"); | 170 | format_args, |
171 | pub const DEBUG_TRAIT: Name = Name::new_inline_ascii(b"Debug"); | 171 | format_args_nl, |
172 | pub const HASH_TRAIT: Name = Name::new_inline_ascii(b"Hash"); | 172 | // Builtin derives |
173 | pub const ORD_TRAIT: Name = Name::new_inline_ascii(b"Ord"); | 173 | Copy, |
174 | pub const PARTIAL_ORD_TRAIT: Name = Name::new_inline_ascii(b"PartialOrd"); | 174 | Clone, |
175 | pub const EQ_TRAIT: Name = Name::new_inline_ascii(b"Eq"); | 175 | Default, |
176 | pub const PARTIAL_EQ_TRAIT: Name = Name::new_inline_ascii(b"PartialEq"); | 176 | Debug, |
177 | Hash, | ||
178 | Ord, | ||
179 | PartialOrd, | ||
180 | Eq, | ||
181 | PartialEq, | ||
182 | ); | ||
183 | |||
184 | // self/Self cannot be used as an identifier | ||
185 | pub const SELF_PARAM: super::Name = super::Name::new_inline_ascii(b"self"); | ||
186 | pub const SELF_TYPE: super::Name = super::Name::new_inline_ascii(b"Self"); | ||
187 | |||
188 | #[macro_export] | ||
189 | macro_rules! N { | ||
190 | (self) => { | ||
191 | $crate::name::known::SELF_PARAM | ||
192 | }; | ||
193 | (Self) => { | ||
194 | $crate::name::known::SELF_TYPE | ||
195 | }; | ||
196 | ($ident:ident) => { | ||
197 | $crate::name::known::$ident | ||
198 | }; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | pub use crate::N; | ||
diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index d557962b4..04822d56e 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | use std::iter::successors; | 6 | use std::iter::successors; |
7 | 7 | ||
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | use hir_expand::name; | 9 | use hir_expand::name::N; |
10 | use log::{info, warn}; | 10 | use log::{info, warn}; |
11 | use ra_db::CrateId; | 11 | use ra_db::CrateId; |
12 | 12 | ||
@@ -52,7 +52,7 @@ fn deref_by_trait( | |||
52 | LangItemTarget::TraitId(it) => it, | 52 | LangItemTarget::TraitId(it) => it, |
53 | _ => return None, | 53 | _ => return None, |
54 | }; | 54 | }; |
55 | let target = db.trait_data(deref_trait).associated_type_by_name(&name::TARGET_TYPE)?; | 55 | let target = db.trait_data(deref_trait).associated_type_by_name(&N![Target])?; |
56 | 56 | ||
57 | let generic_params = generics(db, target.into()); | 57 | let generic_params = generics(db, target.into()); |
58 | if generic_params.len() != 1 { | 58 | if generic_params.len() != 1 { |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index a1201b3e4..bb366bb8b 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -29,7 +29,7 @@ use hir_def::{ | |||
29 | type_ref::{Mutability, TypeRef}, | 29 | type_ref::{Mutability, TypeRef}, |
30 | AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, | 30 | AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, |
31 | }; | 31 | }; |
32 | use hir_expand::{diagnostics::DiagnosticSink, name}; | 32 | use hir_expand::{diagnostics::DiagnosticSink, name::N}; |
33 | use ra_arena::map::ArenaMap; | 33 | use ra_arena::map::ArenaMap; |
34 | use ra_prof::profile; | 34 | use ra_prof::profile; |
35 | 35 | ||
@@ -424,31 +424,31 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
424 | fn resolve_into_iter_item(&self) -> Option<TypeAliasId> { | 424 | fn resolve_into_iter_item(&self) -> Option<TypeAliasId> { |
425 | let path = known::std_iter_into_iterator(); | 425 | let path = known::std_iter_into_iterator(); |
426 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 426 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
427 | self.db.trait_data(trait_).associated_type_by_name(&name::ITEM_TYPE) | 427 | self.db.trait_data(trait_).associated_type_by_name(&N![Item]) |
428 | } | 428 | } |
429 | 429 | ||
430 | fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> { | 430 | fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> { |
431 | let path = known::std_ops_try(); | 431 | let path = known::std_ops_try(); |
432 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 432 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
433 | self.db.trait_data(trait_).associated_type_by_name(&name::OK_TYPE) | 433 | self.db.trait_data(trait_).associated_type_by_name(&N![Ok]) |
434 | } | 434 | } |
435 | 435 | ||
436 | fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> { | 436 | fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> { |
437 | let path = known::std_ops_neg(); | 437 | let path = known::std_ops_neg(); |
438 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 438 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
439 | self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) | 439 | self.db.trait_data(trait_).associated_type_by_name(&N![Output]) |
440 | } | 440 | } |
441 | 441 | ||
442 | fn resolve_ops_not_output(&self) -> Option<TypeAliasId> { | 442 | fn resolve_ops_not_output(&self) -> Option<TypeAliasId> { |
443 | let path = known::std_ops_not(); | 443 | let path = known::std_ops_not(); |
444 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 444 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
445 | self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) | 445 | self.db.trait_data(trait_).associated_type_by_name(&N![Output]) |
446 | } | 446 | } |
447 | 447 | ||
448 | fn resolve_future_future_output(&self) -> Option<TypeAliasId> { | 448 | fn resolve_future_future_output(&self) -> Option<TypeAliasId> { |
449 | let path = known::std_future_future(); | 449 | let path = known::std_future_future(); |
450 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 450 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
451 | self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) | 451 | self.db.trait_data(trait_).associated_type_by_name(&N![Output]) |
452 | } | 452 | } |
453 | 453 | ||
454 | fn resolve_boxed_box(&self) -> Option<AdtId> { | 454 | fn resolve_boxed_box(&self) -> Option<AdtId> { |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index f8c00a7b4..a6f5c6ec3 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -10,7 +10,7 @@ use hir_def::{ | |||
10 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
11 | AdtId, ContainerId, Lookup, StructFieldId, | 11 | AdtId, ContainerId, Lookup, StructFieldId, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{self, Name}; | 13 | use hir_expand::name::{Name, N}; |
14 | use ra_syntax::ast::RangeOp; | 14 | use ra_syntax::ast::RangeOp; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
@@ -631,7 +631,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
631 | // Parent arguments are unknown, except for the receiver type | 631 | // Parent arguments are unknown, except for the receiver type |
632 | if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { | 632 | if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { |
633 | for (_id, param) in parent_generics { | 633 | for (_id, param) in parent_generics { |
634 | if param.name == name::SELF_TYPE { | 634 | if param.name == N![Self] { |
635 | substs.push(receiver_ty.clone()); | 635 | substs.push(receiver_ty.clone()); |
636 | } else { | 636 | } else { |
637 | substs.push(Ty::Unknown); | 637 | substs.push(Ty::Unknown); |
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 598fd81e3..27c475a3c 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! This module provides the built-in trait implementations, e.g. to make | 1 | //! This module provides the built-in trait implementations, e.g. to make |
2 | //! closures implement `Fn`. | 2 | //! closures implement `Fn`. |
3 | use hir_def::{expr::Expr, lang_item::LangItemTarget, TraitId, TypeAliasId}; | 3 | use hir_def::{expr::Expr, lang_item::LangItemTarget, TraitId, TypeAliasId}; |
4 | use hir_expand::name; | 4 | use hir_expand::name::N; |
5 | use ra_db::CrateId; | 5 | use ra_db::CrateId; |
6 | 6 | ||
7 | use super::{AssocTyValue, Impl}; | 7 | use super::{AssocTyValue, Impl}; |
@@ -79,7 +79,7 @@ fn closure_fn_trait_impl_datum( | |||
79 | // and don't want to return a valid value only to find out later that FnOnce | 79 | // and don't want to return a valid value only to find out later that FnOnce |
80 | // is broken | 80 | // is broken |
81 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; | 81 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; |
82 | let _output = db.trait_data(fn_once_trait).associated_type_by_name(&name::OUTPUT_TYPE)?; | 82 | let _output = db.trait_data(fn_once_trait).associated_type_by_name(&N![Output])?; |
83 | 83 | ||
84 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { | 84 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { |
85 | Expr::Lambda { args, .. } => args.len() as u16, | 85 | Expr::Lambda { args, .. } => args.len() as u16, |
@@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
137 | 137 | ||
138 | let output_ty_id = db | 138 | let output_ty_id = db |
139 | .trait_data(fn_once_trait) | 139 | .trait_data(fn_once_trait) |
140 | .associated_type_by_name(&name::OUTPUT_TYPE) | 140 | .associated_type_by_name(&N![Output]) |
141 | .expect("assoc ty value should not exist"); | 141 | .expect("assoc ty value should not exist"); |
142 | 142 | ||
143 | BuiltinImplAssocTyValueData { | 143 | BuiltinImplAssocTyValueData { |
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index aeb211a91..fabf45b53 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs | |||
@@ -10,10 +10,8 @@ use hir_def::{ | |||
10 | type_ref::TypeRef, | 10 | type_ref::TypeRef, |
11 | ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, | 11 | ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{self, Name}; | 13 | use hir_expand::name::{Name, N}; |
14 | 14 | ||
15 | // FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`. | ||
16 | // We should return a `TraitREf` here. | ||
17 | fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | 15 | fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { |
18 | let resolver = trait_.resolver(db); | 16 | let resolver = trait_.resolver(db); |
19 | // returning the iterator directly doesn't easily work because of | 17 | // returning the iterator directly doesn't easily work because of |
@@ -24,7 +22,7 @@ fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | |||
24 | .where_predicates | 22 | .where_predicates |
25 | .iter() | 23 | .iter() |
26 | .filter_map(|pred| match &pred.type_ref { | 24 | .filter_map(|pred| match &pred.type_ref { |
27 | TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(), | 25 | TypeRef::Path(p) if p.as_ident() == Some(&N![Self]) => pred.bound.as_path(), |
28 | _ => None, | 26 | _ => None, |
29 | }) | 27 | }) |
30 | .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { | 28 | .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { |