aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/source_binder.rs4
-rw-r--r--crates/ra_hir_def/src/path.rs95
-rw-r--r--crates/ra_hir_ty/src/expr.rs4
-rw-r--r--crates/ra_hir_ty/src/infer.rs26
4 files changed, 49 insertions, 80 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index d3cc5c423..f82242c3a 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -15,7 +15,7 @@ use hir_def::{
15 }, 15 },
16 expr::{ExprId, PatId}, 16 expr::{ExprId, PatId},
17 nameres::ModuleSource, 17 nameres::ModuleSource,
18 path::known, 18 path::path,
19 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, 19 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
20 AssocItemId, DefWithBodyId, 20 AssocItemId, DefWithBodyId,
21}; 21};
@@ -418,7 +418,7 @@ impl SourceAnalyzer {
418 /// Checks that particular type `ty` implements `std::future::Future`. 418 /// Checks that particular type `ty` implements `std::future::Future`.
419 /// This function is used in `.await` syntax completion. 419 /// This function is used in `.await` syntax completion.
420 pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool { 420 pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool {
421 let std_future_path = known::std_future_future(); 421 let std_future_path = path![std::future::Future];
422 422
423 let std_future_trait = match self.resolver.resolve_known_trait(db, &std_future_path) { 423 let std_future_trait = match self.resolver.resolve_known_trait(db, &std_future_path) {
424 Some(it) => it.into(), 424 Some(it) => it.into(),
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index c1376af36..1e9eb14ea 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -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
@@ -296,64 +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::name; 297
301 298#[macro_export]
302 use super::{Path, PathKind}; 299macro_rules! __known_path {
303 300 (std::iter::IntoIterator) => {};
304 macro_rules! P { 301 (std::result::Result) => {};
305 ($start:ident $(:: $seg:ident)*) => { Path::from_simple_segments(PathKind::Abs, vec![name![$start], $(name![$seg],)*]) }; 302 (std::ops::Range) => {};
306 } 303 (std::ops::RangeFrom) => {};
307 304 (std::ops::RangeFull) => {};
308 pub fn std_iter_into_iterator() -> Path { 305 (std::ops::RangeTo) => {};
309 P![std::iter::IntoIterator] 306 (std::ops::RangeToInclusive) => {};
310 } 307 (std::ops::RangeInclusive) => {};
311 308 (std::boxed::Box) => {};
312 pub fn std_ops_try() -> Path { 309 (std::future::Future) => {};
313 P![std::ops::Try] 310 (std::ops::Try) => {};
314 } 311 (std::ops::Neg) => {};
315 312 (std::ops::Not) => {};
316 pub fn std_ops_range() -> Path { 313 ($path:path) => {
317 P![std::ops::Range] 314 compile_error!("Please register your known path in the path module")
318 } 315 };
319 316}
320 pub fn std_ops_range_from() -> Path {
321 P![std::ops::RangeFrom]
322 }
323
324 pub fn std_ops_range_full() -> Path {
325 P![std::ops::RangeFull]
326 }
327
328 pub fn std_ops_range_inclusive() -> Path {
329 P![std::ops::RangeInclusive]
330 }
331
332 pub fn std_ops_range_to() -> Path {
333 P![std::ops::RangeTo]
334 }
335
336 pub fn std_ops_range_to_inclusive() -> Path {
337 P![std::ops::RangeToInclusive]
338 }
339
340 pub fn std_ops_neg() -> Path {
341 P![std::ops::Neg]
342 }
343
344 pub fn std_ops_not() -> Path {
345 P![std::ops::Not]
346 }
347
348 pub fn std_result_result() -> Path {
349 P![std::result::Result]
350 }
351
352 pub fn std_future_future() -> Path {
353 P![std::future::Future]
354 }
355 317
356 pub fn std_boxed_box() -> Path { 318#[macro_export]
357 P![std::boxed::Box] 319macro_rules! __path {
358 } 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 });
359} 326}
327
328pub use crate::__path as path;
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index d2bd64e5c..f752a9f09 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -3,7 +3,7 @@
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{ 5use hir_def::{
6 path::{known, Path}, 6 path::{path, Path},
7 resolver::HasResolver, 7 resolver::HasResolver,
8 AdtId, FunctionId, 8 AdtId, FunctionId,
9}; 9};
@@ -124,7 +124,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
124 None => return, 124 None => return,
125 }; 125 };
126 126
127 let std_result_path = known::std_result_result(); 127 let std_result_path = path![std::result::Result];
128 128
129 let resolver = self.func.resolver(db); 129 let resolver = self.func.resolver(db);
130 let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { 130 let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) {
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index edf4e69ba..f1b7e9442 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -24,7 +24,7 @@ use hir_def::{
24 body::Body, 24 body::Body,
25 data::{ConstData, FunctionData}, 25 data::{ConstData, FunctionData},
26 expr::{BindingAnnotation, ExprId, PatId}, 26 expr::{BindingAnnotation, ExprId, PatId},
27 path::{known, Path}, 27 path::{path, Path},
28 resolver::{HasResolver, Resolver, TypeNs}, 28 resolver::{HasResolver, Resolver, TypeNs},
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,
@@ -422,73 +422,73 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
422 } 422 }
423 423
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 = path![std::iter::IntoIterator];
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]) 427 self.db.trait_data(trait_).associated_type_by_name(&name![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 = path![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]) 433 self.db.trait_data(trait_).associated_type_by_name(&name![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 = path![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]) 439 self.db.trait_data(trait_).associated_type_by_name(&name![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 = path![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]) 445 self.db.trait_data(trait_).associated_type_by_name(&name![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 = path![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]) 451 self.db.trait_data(trait_).associated_type_by_name(&name![Output])
452 } 452 }
453 453
454 fn resolve_boxed_box(&self) -> Option<AdtId> { 454 fn resolve_boxed_box(&self) -> Option<AdtId> {
455 let path = known::std_boxed_box(); 455 let path = path![std::boxed::Box];
456 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 456 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
457 Some(struct_.into()) 457 Some(struct_.into())
458 } 458 }
459 459
460 fn resolve_range_full(&self) -> Option<AdtId> { 460 fn resolve_range_full(&self) -> Option<AdtId> {
461 let path = known::std_ops_range_full(); 461 let path = path![std::ops::RangeFull];
462 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 462 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
463 Some(struct_.into()) 463 Some(struct_.into())
464 } 464 }
465 465
466 fn resolve_range(&self) -> Option<AdtId> { 466 fn resolve_range(&self) -> Option<AdtId> {
467 let path = known::std_ops_range(); 467 let path = path![std::ops::Range];
468 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 468 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
469 Some(struct_.into()) 469 Some(struct_.into())
470 } 470 }
471 471
472 fn resolve_range_inclusive(&self) -> Option<AdtId> { 472 fn resolve_range_inclusive(&self) -> Option<AdtId> {
473 let path = known::std_ops_range_inclusive(); 473 let path = path![std::ops::RangeInclusive];
474 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 474 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
475 Some(struct_.into()) 475 Some(struct_.into())
476 } 476 }
477 477
478 fn resolve_range_from(&self) -> Option<AdtId> { 478 fn resolve_range_from(&self) -> Option<AdtId> {
479 let path = known::std_ops_range_from(); 479 let path = path![std::ops::RangeFrom];
480 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 480 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
481 Some(struct_.into()) 481 Some(struct_.into())
482 } 482 }
483 483
484 fn resolve_range_to(&self) -> Option<AdtId> { 484 fn resolve_range_to(&self) -> Option<AdtId> {
485 let path = known::std_ops_range_to(); 485 let path = path![std::ops::RangeTo];
486 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 486 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
487 Some(struct_.into()) 487 Some(struct_.into())
488 } 488 }
489 489
490 fn resolve_range_to_inclusive(&self) -> Option<AdtId> { 490 fn resolve_range_to_inclusive(&self) -> Option<AdtId> {
491 let path = known::std_ops_range_to_inclusive(); 491 let path = path![std::ops::RangeToInclusive];
492 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 492 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
493 Some(struct_.into()) 493 Some(struct_.into())
494 } 494 }