aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs4
-rw-r--r--crates/ra_hir_def/src/builtin_type.rs42
-rw-r--r--crates/ra_hir_def/src/data.rs4
-rw-r--r--crates/ra_hir_def/src/generics.rs6
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs4
-rw-r--r--crates/ra_hir_def/src/path.rs104
-rw-r--r--crates/ra_hir_def/src/resolver.rs16
7 files changed, 72 insertions, 108 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index cc068ff94..61193b4d8 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
4use either::Either; 4use either::Either;
5use hir_expand::name::{self, AsName, Name}; 5use hir_expand::name::{name, AsName, Name};
6use ra_arena::Arena; 6use ra_arena::Arena;
7use ra_syntax::{ 7use 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: name![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..d14901a9b 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
6use std::fmt; 6use std::fmt;
7 7
8use hir_expand::name::{self, Name}; 8use hir_expand::name::{name, Name};
9 9
10#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] 10#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
11pub enum Signedness { 11pub enum Signedness {
@@ -52,26 +52,26 @@ pub enum BuiltinType {
52impl BuiltinType { 52impl 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 (name![char], BuiltinType::Char),
56 (name::BOOL, BuiltinType::Bool), 56 (name![bool], BuiltinType::Bool),
57 (name::STR, BuiltinType::Str ), 57 (name![str], BuiltinType::Str),
58 58
59 (name::ISIZE, BuiltinType::Int(BuiltinInt::ISIZE)), 59 (name![isize], BuiltinType::Int(BuiltinInt::ISIZE)),
60 (name::I8, BuiltinType::Int(BuiltinInt::I8)), 60 (name![i8], BuiltinType::Int(BuiltinInt::I8)),
61 (name::I16, BuiltinType::Int(BuiltinInt::I16)), 61 (name![i16], BuiltinType::Int(BuiltinInt::I16)),
62 (name::I32, BuiltinType::Int(BuiltinInt::I32)), 62 (name![i32], BuiltinType::Int(BuiltinInt::I32)),
63 (name::I64, BuiltinType::Int(BuiltinInt::I64)), 63 (name![i64], BuiltinType::Int(BuiltinInt::I64)),
64 (name::I128, BuiltinType::Int(BuiltinInt::I128)), 64 (name![i128], BuiltinType::Int(BuiltinInt::I128)),
65 65
66 (name::USIZE, BuiltinType::Int(BuiltinInt::USIZE)), 66 (name![usize], BuiltinType::Int(BuiltinInt::USIZE)),
67 (name::U8, BuiltinType::Int(BuiltinInt::U8)), 67 (name![u8], BuiltinType::Int(BuiltinInt::U8)),
68 (name::U16, BuiltinType::Int(BuiltinInt::U16)), 68 (name![u16], BuiltinType::Int(BuiltinInt::U16)),
69 (name::U32, BuiltinType::Int(BuiltinInt::U32)), 69 (name![u32], BuiltinType::Int(BuiltinInt::U32)),
70 (name::U64, BuiltinType::Int(BuiltinInt::U64)), 70 (name![u64], BuiltinType::Int(BuiltinInt::U64)),
71 (name::U128, BuiltinType::Int(BuiltinInt::U128)), 71 (name![u128], BuiltinType::Int(BuiltinInt::U128)),
72 72
73 (name::F32, BuiltinType::Float(BuiltinFloat::F32)), 73 (name![f32], BuiltinType::Float(BuiltinFloat::F32)),
74 (name::F64, BuiltinType::Float(BuiltinFloat::F64)), 74 (name![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..4f4ef57cc 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -3,7 +3,7 @@
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_expand::{ 5use hir_expand::{
6 name::{self, AsName, Name}, 6 name::{name, AsName, Name},
7 AstId, 7 AstId,
8}; 8};
9use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 9use 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(name![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..e9c28c730 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
7use either::Either; 7use either::Either;
8use hir_expand::{ 8use hir_expand::{
9 name::{self, AsName, Name}, 9 name::{name, AsName, Name},
10 InFile, 10 InFile,
11}; 11};
12use ra_arena::{map::ArenaMap, Arena}; 12use 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: name![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(name![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..5d7469a6e 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -6,7 +6,7 @@
6use hir_expand::{ 6use 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::{name, AsName, Name},
10 HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, 10 HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
11}; 11};
12use ra_cfg::CfgOptions; 12use ra_cfg::CfgOptions;
@@ -918,7 +918,7 @@ where
918} 918}
919 919
920fn is_macro_rules(path: &Path) -> bool { 920fn is_macro_rules(path: &Path) -> bool {
921 path.as_ident() == Some(&name::MACRO_RULES) 921 path.as_ident() == Some(&name![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..1e9eb14ea 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};
6use either::Either; 6use either::Either;
7use hir_expand::{ 7use hir_expand::{
8 hygiene::Hygiene, 8 hygiene::Hygiene,
9 name::{self, AsName, Name}, 9 name::{name, AsName, Name},
10}; 10};
11use ra_db::CrateId; 11use ra_db::CrateId;
12use ra_syntax::{ 12use ra_syntax::{
@@ -76,10 +76,7 @@ impl Path {
76 } 76 }
77 } 77 }
78 78
79 pub(crate) fn from_simple_segments( 79 pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> Path {
80 kind: PathKind,
81 segments: impl IntoIterator<Item = Name>,
82 ) -> Path {
83 Path { 80 Path {
84 kind, 81 kind,
85 segments: segments 82 segments: segments
@@ -276,7 +273,7 @@ impl GenericArgs {
276 } 273 }
277 if let Some(ret_type) = ret_type { 274 if let Some(ret_type) = ret_type {
278 let type_ref = TypeRef::from_ast_opt(ret_type.type_ref()); 275 let type_ref = TypeRef::from_ast_opt(ret_type.type_ref());
279 bindings.push((name::OUTPUT_TYPE, type_ref)) 276 bindings.push((name![Output], type_ref))
280 } 277 }
281 if args.is_empty() && bindings.is_empty() { 278 if args.is_empty() && bindings.is_empty() {
282 None 279 None
@@ -296,69 +293,36 @@ impl From<Name> for Path {
296 } 293 }
297} 294}
298 295
299pub mod known { 296pub use hir_expand::name as __name;
300 use hir_expand::name; 297
301 298#[macro_export]
302 use super::{Path, PathKind}; 299macro_rules! __known_path {
303 300 (std::iter::IntoIterator) => {};
304 pub fn std_iter_into_iterator() -> Path { 301 (std::result::Result) => {};
305 Path::from_simple_segments( 302 (std::ops::Range) => {};
306 PathKind::Abs, 303 (std::ops::RangeFrom) => {};
307 vec![name::STD, name::ITER, name::INTO_ITERATOR_TYPE], 304 (std::ops::RangeFull) => {};
308 ) 305 (std::ops::RangeTo) => {};
309 } 306 (std::ops::RangeToInclusive) => {};
310 307 (std::ops::RangeInclusive) => {};
311 pub fn std_ops_try() -> Path { 308 (std::boxed::Box) => {};
312 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::TRY_TYPE]) 309 (std::future::Future) => {};
313 } 310 (std::ops::Try) => {};
314 311 (std::ops::Neg) => {};
315 pub fn std_ops_range() -> Path { 312 (std::ops::Not) => {};
316 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_TYPE]) 313 ($path:path) => {
317 } 314 compile_error!("Please register your known path in the path module")
318 315 };
319 pub fn std_ops_range_from() -> Path { 316}
320 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_FROM_TYPE])
321 }
322
323 pub fn std_ops_range_full() -> Path {
324 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_FULL_TYPE])
325 }
326
327 pub fn std_ops_range_inclusive() -> Path {
328 Path::from_simple_segments(
329 PathKind::Abs,
330 vec![name::STD, name::OPS, name::RANGE_INCLUSIVE_TYPE],
331 )
332 }
333
334 pub fn std_ops_range_to() -> Path {
335 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_TO_TYPE])
336 }
337
338 pub fn std_ops_range_to_inclusive() -> Path {
339 Path::from_simple_segments(
340 PathKind::Abs,
341 vec![name::STD, name::OPS, name::RANGE_TO_INCLUSIVE_TYPE],
342 )
343 }
344
345 pub fn std_ops_neg() -> Path {
346 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::NEG_TYPE])
347 }
348
349 pub fn std_ops_not() -> Path {
350 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::NOT_TYPE])
351 }
352
353 pub fn std_result_result() -> Path {
354 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::RESULT, name::RESULT_TYPE])
355 }
356
357 pub fn std_future_future() -> Path {
358 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::FUTURE, name::FUTURE_TYPE])
359 }
360 317
361 pub fn std_boxed_box() -> Path { 318#[macro_export]
362 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::BOXED, name::BOX_TYPE]) 319macro_rules! __path {
363 } 320 ($start:ident $(:: $seg:ident)*) => ({
321 $crate::__known_path!($start $(:: $seg)*);
322 $crate::path::Path::from_simple_segments($crate::path::PathKind::Abs, vec![
323 $crate::path::__name![$start], $($crate::path::__name![$seg],)*
324 ])
325 });
364} 326}
327
328pub use crate::__path as path;
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 17b2169d2..b6d595a20 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -2,7 +2,7 @@
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use hir_expand::{ 4use hir_expand::{
5 name::{self, Name}, 5 name::{name, Name},
6 MacroDefId, 6 MacroDefId,
7}; 7};
8use ra_db::CrateId; 8use 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 == &name![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 == &name![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 = name![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 == &name![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 == &name![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(name![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(name![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| {