aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/path.rs')
-rw-r--r--crates/ra_hir_def/src/path.rs96
1 files changed, 34 insertions, 62 deletions
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index ec9d13e82..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,61 +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_result_result() -> Path {
346 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::RESULT, name::RESULT_TYPE])
347 }
348
349 pub fn std_future_future() -> Path {
350 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::FUTURE, name::FUTURE_TYPE])
351 }
352 317
353 pub fn std_boxed_box() -> Path { 318#[macro_export]
354 Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::BOXED, name::BOX_TYPE]) 319macro_rules! __path {
355 } 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 });
356} 326}
327
328pub use crate::__path as path;