aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs2
-rw-r--r--crates/ra_hir_def/src/body/scope.rs2
-rw-r--r--crates/ra_hir_def/src/resolver.rs107
3 files changed, 45 insertions, 66 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 77f091288..d8e911aa5 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -154,7 +154,6 @@ where
154 None => self.collect_expr_opt(condition.expr()), 154 None => self.collect_expr_opt(condition.expr()),
155 // if let -- desugar to match 155 // if let -- desugar to match
156 Some(pat) => { 156 Some(pat) => {
157 tested_by!(infer_resolve_while_let);
158 let pat = self.collect_pat(pat); 157 let pat = self.collect_pat(pat);
159 let match_expr = self.collect_expr_opt(condition.expr()); 158 let match_expr = self.collect_expr_opt(condition.expr());
160 let placeholder_pat = self.missing_pat(); 159 let placeholder_pat = self.missing_pat();
@@ -192,6 +191,7 @@ where
192 None => self.collect_expr_opt(condition.expr()), 191 None => self.collect_expr_opt(condition.expr()),
193 // if let -- desugar to match 192 // if let -- desugar to match
194 Some(pat) => { 193 Some(pat) => {
194 tested_by!(infer_resolve_while_let);
195 let pat = self.collect_pat(pat); 195 let pat = self.collect_pat(pat);
196 let match_expr = self.collect_expr_opt(condition.expr()); 196 let match_expr = self.collect_expr_opt(condition.expr());
197 let placeholder_pat = self.missing_pat(); 197 let placeholder_pat = self.missing_pat();
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index 5d7d17231..58740b679 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -384,7 +384,7 @@ mod tests {
384 } 384 }
385 385
386 #[test] 386 #[test]
387 fn infer_resolve_while_let() { 387 fn while_let_desugaring() {
388 covers!(infer_resolve_while_let); 388 covers!(infer_resolve_while_let);
389 do_check_local_name( 389 do_check_local_name(
390 r#" 390 r#"
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 840785baa..7b5c3ec06 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -18,7 +18,7 @@ use crate::{
18 path::{Path, PathKind}, 18 path::{Path, PathKind},
19 AdtId, AstItemDef, ConstId, ContainerId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId, 19 AdtId, AstItemDef, ConstId, ContainerId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId,
20 FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, 20 FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId,
21 TypeAliasId, UnionId, 21 TypeAliasId,
22}; 22};
23 23
24#[derive(Debug, Clone, Default)] 24#[derive(Debug, Clone, Default)]
@@ -369,47 +369,6 @@ impl Resolver {
369 } 369 }
370} 370}
371 371
372impl Resolver {
373 pub(crate) fn push_scope(mut self, scope: Scope) -> Resolver {
374 self.scopes.push(scope);
375 self
376 }
377
378 pub(crate) fn push_generic_params_scope(
379 self,
380 db: &impl DefDatabase2,
381 def: GenericDefId,
382 ) -> Resolver {
383 let params = db.generic_params(def);
384 if params.params.is_empty() {
385 self
386 } else {
387 self.push_scope(Scope::GenericParams { def, params })
388 }
389 }
390
391 pub(crate) fn push_impl_block_scope(self, impl_block: ImplId) -> Resolver {
392 self.push_scope(Scope::ImplBlockScope(impl_block))
393 }
394
395 pub(crate) fn push_module_scope(
396 self,
397 crate_def_map: Arc<CrateDefMap>,
398 module_id: CrateModuleId,
399 ) -> Resolver {
400 self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
401 }
402
403 pub(crate) fn push_expr_scope(
404 self,
405 owner: DefWithBodyId,
406 expr_scopes: Arc<ExprScopes>,
407 scope_id: ScopeId,
408 ) -> Resolver {
409 self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
410 }
411}
412
413pub enum ScopeDef { 372pub enum ScopeDef {
414 PerNs(PerNs), 373 PerNs(PerNs),
415 ImplSelfType(ImplId), 374 ImplSelfType(ImplId),
@@ -489,6 +448,43 @@ pub fn resolver_for_scope(
489 r 448 r
490} 449}
491 450
451impl Resolver {
452 fn push_scope(mut self, scope: Scope) -> Resolver {
453 self.scopes.push(scope);
454 self
455 }
456
457 fn push_generic_params_scope(self, db: &impl DefDatabase2, def: GenericDefId) -> Resolver {
458 let params = db.generic_params(def);
459 if params.params.is_empty() {
460 self
461 } else {
462 self.push_scope(Scope::GenericParams { def, params })
463 }
464 }
465
466 fn push_impl_block_scope(self, impl_block: ImplId) -> Resolver {
467 self.push_scope(Scope::ImplBlockScope(impl_block))
468 }
469
470 fn push_module_scope(
471 self,
472 crate_def_map: Arc<CrateDefMap>,
473 module_id: CrateModuleId,
474 ) -> Resolver {
475 self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
476 }
477
478 fn push_expr_scope(
479 self,
480 owner: DefWithBodyId,
481 expr_scopes: Arc<ExprScopes>,
482 scope_id: ScopeId,
483 ) -> Resolver {
484 self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
485 }
486}
487
492pub trait HasResolver { 488pub trait HasResolver {
493 /// Builds a resolver for type references inside this def. 489 /// Builds a resolver for type references inside this def.
494 fn resolver(self, db: &impl DefDatabase2) -> Resolver; 490 fn resolver(self, db: &impl DefDatabase2) -> Resolver;
@@ -507,9 +503,10 @@ impl HasResolver for TraitId {
507 } 503 }
508} 504}
509 505
510impl HasResolver for AdtId { 506impl<T: Into<AdtId>> HasResolver for T {
511 fn resolver(self, db: &impl DefDatabase2) -> Resolver { 507 fn resolver(self, db: &impl DefDatabase2) -> Resolver {
512 let module = match self { 508 let def = self.into();
509 let module = match def {
513 AdtId::StructId(it) => it.0.module(db), 510 AdtId::StructId(it) => it.0.module(db),
514 AdtId::UnionId(it) => it.0.module(db), 511 AdtId::UnionId(it) => it.0.module(db),
515 AdtId::EnumId(it) => it.module(db), 512 AdtId::EnumId(it) => it.module(db),
@@ -517,26 +514,8 @@ impl HasResolver for AdtId {
517 514
518 module 515 module
519 .resolver(db) 516 .resolver(db)
520 .push_generic_params_scope(db, self.into()) 517 .push_generic_params_scope(db, def.into())
521 .push_scope(Scope::AdtScope(self.into())) 518 .push_scope(Scope::AdtScope(def))
522 }
523}
524
525impl HasResolver for StructId {
526 fn resolver(self, db: &impl DefDatabase2) -> Resolver {
527 AdtId::from(self).resolver(db)
528 }
529}
530
531impl HasResolver for UnionId {
532 fn resolver(self, db: &impl DefDatabase2) -> Resolver {
533 AdtId::from(self).resolver(db)
534 }
535}
536
537impl HasResolver for EnumId {
538 fn resolver(self, db: &impl DefDatabase2) -> Resolver {
539 AdtId::from(self).resolver(db)
540 } 519 }
541} 520}
542 521