Skip to content

Commit e05fc94

Browse files
bors[bot]matklad
andauthored
Merge #2253
2253: Reduce visibility r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 31d01ef + 487fc44 commit e05fc94

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

crates/ra_hir/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) fn resolver_for_scope(
3838
let scopes = owner.expr_scopes(db);
3939
let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
4040
for scope in scope_chain.into_iter().rev() {
41-
r = r.push_expr_scope(Arc::clone(&scopes), scope);
41+
r = r.push_expr_scope(owner, Arc::clone(&scopes), scope);
4242
}
4343
r
4444
}

crates/ra_hir/src/resolve.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::{
1616
expr::{ExprScopes, PatId, ScopeId},
1717
generics::GenericParams,
1818
impl_block::ImplBlock,
19-
Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, PerNs, Static, Struct, Trait,
20-
TypeAlias,
19+
Adt, Const, DefWithBody, Enum, EnumVariant, Function, Local, MacroDef, ModuleDef, PerNs,
20+
Static, Struct, Trait, TypeAlias,
2121
};
2222

2323
#[derive(Debug, Clone, Default)]
@@ -34,6 +34,7 @@ pub(crate) struct ModuleItemMap {
3434

3535
#[derive(Debug, Clone)]
3636
pub(crate) struct ExprScope {
37+
owner: DefWithBody,
3738
expr_scopes: Arc<ExprScopes>,
3839
scope_id: ScopeId,
3940
}
@@ -53,7 +54,7 @@ pub(crate) enum Scope {
5354
}
5455

5556
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
56-
pub enum TypeNs {
57+
pub(crate) enum TypeNs {
5758
SelfType(ImplBlock),
5859
GenericParam(u32),
5960
Adt(Adt),
@@ -68,13 +69,13 @@ pub enum TypeNs {
6869
}
6970

7071
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
71-
pub enum ResolveValueResult {
72+
pub(crate) enum ResolveValueResult {
7273
ValueNs(ValueNs),
7374
Partial(TypeNs, usize),
7475
}
7576

7677
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
77-
pub enum ValueNs {
78+
pub(crate) enum ValueNs {
7879
LocalBinding(PatId),
7980
Function(Function),
8081
Const(Const),
@@ -399,10 +400,11 @@ impl Resolver {
399400

400401
pub(crate) fn push_expr_scope(
401402
self,
403+
owner: DefWithBody,
402404
expr_scopes: Arc<ExprScopes>,
403405
scope_id: ScopeId,
404406
) -> Resolver {
405-
self.push_scope(Scope::ExprScope(ExprScope { expr_scopes, scope_id }))
407+
self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
406408
}
407409
}
408410

@@ -413,7 +415,7 @@ pub enum ScopeDef {
413415
GenericParam(u32),
414416
ImplSelfType(ImplBlock),
415417
AdtSelfType(Adt),
416-
LocalBinding(PatId),
418+
Local(Local),
417419
Unknown,
418420
}
419421

@@ -467,9 +469,10 @@ impl Scope {
467469
Scope::AdtScope(i) => {
468470
f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i));
469471
}
470-
Scope::ExprScope(e) => {
471-
e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {
472-
f(e.name().clone(), ScopeDef::LocalBinding(e.pat()));
472+
Scope::ExprScope(scope) => {
473+
scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| {
474+
let local = Local { parent: scope.owner, pat_id: e.pat() };
475+
f(e.name().clone(), ScopeDef::Local(local));
473476
});
474477
}
475478
}

crates/ra_hir/src/source_binder.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,6 @@ impl SourceAnalyzer {
195195
Some(self.infer.as_ref()?[pat_id].clone())
196196
}
197197

198-
pub fn type_of_pat_by_id(
199-
&self,
200-
_db: &impl HirDatabase,
201-
pat_id: expr::PatId,
202-
) -> Option<crate::Ty> {
203-
Some(self.infer.as_ref()?[pat_id].clone())
204-
}
205-
206198
pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
207199
let expr_id = self.expr_id(&call.clone().into())?;
208200
self.infer.as_ref()?.method_resolution(expr_id)

crates/ra_ide_api/src/completion/presentation.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Completions {
6868
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias,
6969
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
7070
ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam,
71-
ScopeDef::LocalBinding(..) => CompletionItemKind::Binding,
71+
ScopeDef::Local(..) => CompletionItemKind::Binding,
7272
// (does this need its own kind?)
7373
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
7474
ScopeDef::MacroDef(mac) => {
@@ -96,13 +96,11 @@ impl Completions {
9696

9797
let mut completion_item =
9898
CompletionItem::new(completion_kind, ctx.source_range(), local_name.clone());
99-
if let ScopeDef::LocalBinding(pat_id) = resolution {
100-
let ty = ctx
101-
.analyzer
102-
.type_of_pat_by_id(ctx.db, pat_id.clone())
103-
.filter(|t| t != &Ty::Unknown)
104-
.map(|t| t.display(ctx.db).to_string());
105-
completion_item = completion_item.set_detail(ty);
99+
if let ScopeDef::Local(local) = resolution {
100+
let ty = local.ty(ctx.db);
101+
if ty != Ty::Unknown {
102+
completion_item = completion_item.detail(ty.display(ctx.db).to_string());
103+
}
106104
};
107105

108106
// If not an import, add parenthesis automatically.

0 commit comments

Comments
 (0)