diff options
Diffstat (limited to 'crates/ra_hir_def/src/resolver.rs')
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 123fae72a..717506358 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -96,7 +96,7 @@ pub enum ValueNs { | |||
96 | 96 | ||
97 | impl Resolver { | 97 | impl Resolver { |
98 | /// Resolve known trait from std, like `std::futures::Future` | 98 | /// Resolve known trait from std, like `std::futures::Future` |
99 | pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &ModPath) -> Option<TraitId> { | 99 | pub fn resolve_known_trait(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<TraitId> { |
100 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; | 100 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; |
101 | match res { | 101 | match res { |
102 | ModuleDefId::TraitId(it) => Some(it), | 102 | ModuleDefId::TraitId(it) => Some(it), |
@@ -105,7 +105,7 @@ impl Resolver { | |||
105 | } | 105 | } |
106 | 106 | ||
107 | /// Resolve known struct from std, like `std::boxed::Box` | 107 | /// Resolve known struct from std, like `std::boxed::Box` |
108 | pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &ModPath) -> Option<StructId> { | 108 | pub fn resolve_known_struct(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<StructId> { |
109 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; | 109 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; |
110 | match res { | 110 | match res { |
111 | ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), | 111 | ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), |
@@ -114,7 +114,7 @@ impl Resolver { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | /// Resolve known enum from std, like `std::result::Result` | 116 | /// Resolve known enum from std, like `std::result::Result` |
117 | pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &ModPath) -> Option<EnumId> { | 117 | pub fn resolve_known_enum(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<EnumId> { |
118 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; | 118 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; |
119 | match res { | 119 | match res { |
120 | ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), | 120 | ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), |
@@ -124,7 +124,7 @@ impl Resolver { | |||
124 | 124 | ||
125 | fn resolve_module_path( | 125 | fn resolve_module_path( |
126 | &self, | 126 | &self, |
127 | db: &impl DefDatabase, | 127 | db: &dyn DefDatabase, |
128 | path: &ModPath, | 128 | path: &ModPath, |
129 | shadow: BuiltinShadowMode, | 129 | shadow: BuiltinShadowMode, |
130 | ) -> PerNs { | 130 | ) -> PerNs { |
@@ -139,13 +139,13 @@ impl Resolver { | |||
139 | module_res | 139 | module_res |
140 | } | 140 | } |
141 | 141 | ||
142 | pub fn resolve_module_path_in_items(&self, db: &impl DefDatabase, path: &ModPath) -> PerNs { | 142 | pub fn resolve_module_path_in_items(&self, db: &dyn DefDatabase, path: &ModPath) -> PerNs { |
143 | self.resolve_module_path(db, path, BuiltinShadowMode::Module) | 143 | self.resolve_module_path(db, path, BuiltinShadowMode::Module) |
144 | } | 144 | } |
145 | 145 | ||
146 | pub fn resolve_path_in_type_ns( | 146 | pub fn resolve_path_in_type_ns( |
147 | &self, | 147 | &self, |
148 | db: &impl DefDatabase, | 148 | db: &dyn DefDatabase, |
149 | path: &ModPath, | 149 | path: &ModPath, |
150 | ) -> Option<(TypeNs, Option<usize>)> { | 150 | ) -> Option<(TypeNs, Option<usize>)> { |
151 | let first_name = path.segments.first()?; | 151 | let first_name = path.segments.first()?; |
@@ -222,7 +222,7 @@ impl Resolver { | |||
222 | 222 | ||
223 | pub fn resolve_path_in_type_ns_fully( | 223 | pub fn resolve_path_in_type_ns_fully( |
224 | &self, | 224 | &self, |
225 | db: &impl DefDatabase, | 225 | db: &dyn DefDatabase, |
226 | path: &ModPath, | 226 | path: &ModPath, |
227 | ) -> Option<TypeNs> { | 227 | ) -> Option<TypeNs> { |
228 | let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?; | 228 | let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?; |
@@ -234,7 +234,7 @@ impl Resolver { | |||
234 | 234 | ||
235 | pub fn resolve_visibility( | 235 | pub fn resolve_visibility( |
236 | &self, | 236 | &self, |
237 | db: &impl DefDatabase, | 237 | db: &dyn DefDatabase, |
238 | visibility: &RawVisibility, | 238 | visibility: &RawVisibility, |
239 | ) -> Option<Visibility> { | 239 | ) -> Option<Visibility> { |
240 | match visibility { | 240 | match visibility { |
@@ -251,7 +251,7 @@ impl Resolver { | |||
251 | 251 | ||
252 | pub fn resolve_path_in_value_ns( | 252 | pub fn resolve_path_in_value_ns( |
253 | &self, | 253 | &self, |
254 | db: &impl DefDatabase, | 254 | db: &dyn DefDatabase, |
255 | path: &ModPath, | 255 | path: &ModPath, |
256 | ) -> Option<ResolveValueResult> { | 256 | ) -> Option<ResolveValueResult> { |
257 | let n_segments = path.segments.len(); | 257 | let n_segments = path.segments.len(); |
@@ -367,7 +367,7 @@ impl Resolver { | |||
367 | 367 | ||
368 | pub fn resolve_path_in_value_ns_fully( | 368 | pub fn resolve_path_in_value_ns_fully( |
369 | &self, | 369 | &self, |
370 | db: &impl DefDatabase, | 370 | db: &dyn DefDatabase, |
371 | path: &ModPath, | 371 | path: &ModPath, |
372 | ) -> Option<ValueNs> { | 372 | ) -> Option<ValueNs> { |
373 | match self.resolve_path_in_value_ns(db, path)? { | 373 | match self.resolve_path_in_value_ns(db, path)? { |
@@ -378,7 +378,7 @@ impl Resolver { | |||
378 | 378 | ||
379 | pub fn resolve_path_as_macro( | 379 | pub fn resolve_path_as_macro( |
380 | &self, | 380 | &self, |
381 | db: &impl DefDatabase, | 381 | db: &dyn DefDatabase, |
382 | path: &ModPath, | 382 | path: &ModPath, |
383 | ) -> Option<MacroDefId> { | 383 | ) -> Option<MacroDefId> { |
384 | // Search item scope legacy macro first | 384 | // Search item scope legacy macro first |
@@ -390,13 +390,13 @@ impl Resolver { | |||
390 | item_map.resolve_path(db, module, &path, BuiltinShadowMode::Other).0.take_macros() | 390 | item_map.resolve_path(db, module, &path, BuiltinShadowMode::Other).0.take_macros() |
391 | } | 391 | } |
392 | 392 | ||
393 | pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { | 393 | pub fn process_all_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { |
394 | for scope in self.scopes.iter().rev() { | 394 | for scope in self.scopes.iter().rev() { |
395 | scope.process_names(db, f); | 395 | scope.process_names(db, f); |
396 | } | 396 | } |
397 | } | 397 | } |
398 | 398 | ||
399 | pub fn traits_in_scope(&self, db: &impl DefDatabase) -> FxHashSet<TraitId> { | 399 | pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> { |
400 | let mut traits = FxHashSet::default(); | 400 | let mut traits = FxHashSet::default(); |
401 | for scope in &self.scopes { | 401 | for scope in &self.scopes { |
402 | if let Scope::ModuleScope(m) = scope { | 402 | if let Scope::ModuleScope(m) = scope { |
@@ -474,7 +474,7 @@ pub enum ScopeDef { | |||
474 | } | 474 | } |
475 | 475 | ||
476 | impl Scope { | 476 | impl Scope { |
477 | fn process_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { | 477 | fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { |
478 | match self { | 478 | match self { |
479 | Scope::ModuleScope(m) => { | 479 | Scope::ModuleScope(m) => { |
480 | // FIXME: should we provide `self` here? | 480 | // FIXME: should we provide `self` here? |
@@ -534,13 +534,13 @@ impl Scope { | |||
534 | } | 534 | } |
535 | 535 | ||
536 | // needs arbitrary_self_types to be a method... or maybe move to the def? | 536 | // needs arbitrary_self_types to be a method... or maybe move to the def? |
537 | pub fn resolver_for_expr(db: &impl DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver { | 537 | pub fn resolver_for_expr(db: &dyn DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver { |
538 | let scopes = db.expr_scopes(owner); | 538 | let scopes = db.expr_scopes(owner); |
539 | resolver_for_scope(db, owner, scopes.scope_for(expr_id)) | 539 | resolver_for_scope(db, owner, scopes.scope_for(expr_id)) |
540 | } | 540 | } |
541 | 541 | ||
542 | pub fn resolver_for_scope( | 542 | pub fn resolver_for_scope( |
543 | db: &impl DefDatabase, | 543 | db: &dyn DefDatabase, |
544 | owner: DefWithBodyId, | 544 | owner: DefWithBodyId, |
545 | scope_id: Option<ScopeId>, | 545 | scope_id: Option<ScopeId>, |
546 | ) -> Resolver { | 546 | ) -> Resolver { |
@@ -560,7 +560,7 @@ impl Resolver { | |||
560 | self | 560 | self |
561 | } | 561 | } |
562 | 562 | ||
563 | fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { | 563 | fn push_generic_params_scope(self, db: &dyn DefDatabase, def: GenericDefId) -> Resolver { |
564 | let params = db.generic_params(def); | 564 | let params = db.generic_params(def); |
565 | self.push_scope(Scope::GenericParams { def, params }) | 565 | self.push_scope(Scope::GenericParams { def, params }) |
566 | } | 566 | } |
@@ -593,24 +593,24 @@ impl Resolver { | |||
593 | 593 | ||
594 | pub trait HasResolver: Copy { | 594 | pub trait HasResolver: Copy { |
595 | /// Builds a resolver for type references inside this def. | 595 | /// Builds a resolver for type references inside this def. |
596 | fn resolver(self, db: &impl DefDatabase) -> Resolver; | 596 | fn resolver(self, db: &dyn DefDatabase) -> Resolver; |
597 | } | 597 | } |
598 | 598 | ||
599 | impl HasResolver for ModuleId { | 599 | impl HasResolver for ModuleId { |
600 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 600 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
601 | let def_map = db.crate_def_map(self.krate); | 601 | let def_map = db.crate_def_map(self.krate); |
602 | Resolver::default().push_module_scope(def_map, self.local_id) | 602 | Resolver::default().push_module_scope(def_map, self.local_id) |
603 | } | 603 | } |
604 | } | 604 | } |
605 | 605 | ||
606 | impl HasResolver for TraitId { | 606 | impl HasResolver for TraitId { |
607 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 607 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
608 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) | 608 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) |
609 | } | 609 | } |
610 | } | 610 | } |
611 | 611 | ||
612 | impl<T: Into<AdtId> + Copy> HasResolver for T { | 612 | impl<T: Into<AdtId> + Copy> HasResolver for T { |
613 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 613 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
614 | let def = self.into(); | 614 | let def = self.into(); |
615 | def.module(db) | 615 | def.module(db) |
616 | .resolver(db) | 616 | .resolver(db) |
@@ -620,31 +620,31 @@ impl<T: Into<AdtId> + Copy> HasResolver for T { | |||
620 | } | 620 | } |
621 | 621 | ||
622 | impl HasResolver for FunctionId { | 622 | impl HasResolver for FunctionId { |
623 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 623 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
624 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) | 624 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) |
625 | } | 625 | } |
626 | } | 626 | } |
627 | 627 | ||
628 | impl HasResolver for ConstId { | 628 | impl HasResolver for ConstId { |
629 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 629 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
630 | self.lookup(db).container.resolver(db) | 630 | self.lookup(db).container.resolver(db) |
631 | } | 631 | } |
632 | } | 632 | } |
633 | 633 | ||
634 | impl HasResolver for StaticId { | 634 | impl HasResolver for StaticId { |
635 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 635 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
636 | self.lookup(db).container.resolver(db) | 636 | self.lookup(db).container.resolver(db) |
637 | } | 637 | } |
638 | } | 638 | } |
639 | 639 | ||
640 | impl HasResolver for TypeAliasId { | 640 | impl HasResolver for TypeAliasId { |
641 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 641 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
642 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) | 642 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) |
643 | } | 643 | } |
644 | } | 644 | } |
645 | 645 | ||
646 | impl HasResolver for ImplId { | 646 | impl HasResolver for ImplId { |
647 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 647 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
648 | self.lookup(db) | 648 | self.lookup(db) |
649 | .container | 649 | .container |
650 | .resolver(db) | 650 | .resolver(db) |
@@ -654,7 +654,7 @@ impl HasResolver for ImplId { | |||
654 | } | 654 | } |
655 | 655 | ||
656 | impl HasResolver for DefWithBodyId { | 656 | impl HasResolver for DefWithBodyId { |
657 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 657 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
658 | match self { | 658 | match self { |
659 | DefWithBodyId::ConstId(c) => c.resolver(db), | 659 | DefWithBodyId::ConstId(c) => c.resolver(db), |
660 | DefWithBodyId::FunctionId(f) => f.resolver(db), | 660 | DefWithBodyId::FunctionId(f) => f.resolver(db), |
@@ -664,7 +664,7 @@ impl HasResolver for DefWithBodyId { | |||
664 | } | 664 | } |
665 | 665 | ||
666 | impl HasResolver for ContainerId { | 666 | impl HasResolver for ContainerId { |
667 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 667 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
668 | match self { | 668 | match self { |
669 | ContainerId::ModuleId(it) => it.resolver(db), | 669 | ContainerId::ModuleId(it) => it.resolver(db), |
670 | ContainerId::DefWithBodyId(it) => it.module(db).resolver(db), | 670 | ContainerId::DefWithBodyId(it) => it.module(db).resolver(db), |
@@ -673,7 +673,7 @@ impl HasResolver for ContainerId { | |||
673 | } | 673 | } |
674 | 674 | ||
675 | impl HasResolver for AssocContainerId { | 675 | impl HasResolver for AssocContainerId { |
676 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 676 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
677 | match self { | 677 | match self { |
678 | AssocContainerId::ContainerId(it) => it.resolver(db), | 678 | AssocContainerId::ContainerId(it) => it.resolver(db), |
679 | AssocContainerId::TraitId(it) => it.resolver(db), | 679 | AssocContainerId::TraitId(it) => it.resolver(db), |
@@ -683,7 +683,7 @@ impl HasResolver for AssocContainerId { | |||
683 | } | 683 | } |
684 | 684 | ||
685 | impl HasResolver for GenericDefId { | 685 | impl HasResolver for GenericDefId { |
686 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 686 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
687 | match self { | 687 | match self { |
688 | GenericDefId::FunctionId(inner) => inner.resolver(db), | 688 | GenericDefId::FunctionId(inner) => inner.resolver(db), |
689 | GenericDefId::AdtId(adt) => adt.resolver(db), | 689 | GenericDefId::AdtId(adt) => adt.resolver(db), |
@@ -697,7 +697,7 @@ impl HasResolver for GenericDefId { | |||
697 | } | 697 | } |
698 | 698 | ||
699 | impl HasResolver for VariantId { | 699 | impl HasResolver for VariantId { |
700 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 700 | fn resolver(self, db: &dyn DefDatabase) -> Resolver { |
701 | match self { | 701 | match self { |
702 | VariantId::EnumVariantId(it) => it.parent.resolver(db), | 702 | VariantId::EnumVariantId(it) => it.parent.resolver(db), |
703 | VariantId::StructId(it) => it.resolver(db), | 703 | VariantId::StructId(it) => it.resolver(db), |