Skip to content

Commit 2906d18

Browse files
committed
Cleanup
1 parent 38cd9f0 commit 2906d18

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

crates/ra_hir_def/src/find_path.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ use crate::{
99
};
1010
use hir_expand::name::Name;
1111

12+
const MAX_PATH_LEN: usize = 15;
13+
1214
pub fn find_path(db: &impl DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
13-
find_path_inner(db, item, from, 15)
15+
find_path_inner(db, item, from, MAX_PATH_LEN)
1416
}
1517

16-
fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_len: usize) -> Option<ModPath> {
17-
// Base cases:
18-
18+
fn find_path_inner(
19+
db: &impl DefDatabase,
20+
item: ItemInNs,
21+
from: ModuleId,
22+
max_len: usize,
23+
) -> Option<ModPath> {
1924
if max_len == 0 {
2025
return None;
2126
}
2227

28+
// Base cases:
29+
2330
// - if the item is already in scope, return the name under which it is
2431
let def_map = db.crate_def_map(from.krate);
2532
let from_scope: &crate::item_scope::ItemScope = &def_map.modules[from.local_id].scope;
@@ -86,8 +93,12 @@ fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_le
8693
let mut best_path = None;
8794
let mut best_path_len = max_len;
8895
for (module_id, name) in importable_locations {
89-
let mut path = match find_path_inner(db, ItemInNs::Types(ModuleDefId::ModuleId(module_id)), from, best_path_len - 1)
90-
{
96+
let mut path = match find_path_inner(
97+
db,
98+
ItemInNs::Types(ModuleDefId::ModuleId(module_id)),
99+
from,
100+
best_path_len - 1,
101+
) {
91102
None => continue,
92103
Some(path) => path,
93104
};
@@ -101,13 +112,14 @@ fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_le
101112
}
102113

103114
fn path_len(path: &ModPath) -> usize {
104-
path.segments.len() + match path.kind {
105-
PathKind::Plain => 0,
106-
PathKind::Super(i) => i as usize,
107-
PathKind::Crate => 1,
108-
PathKind::Abs => 0,
109-
PathKind::DollarCrate(_) => 1,
110-
}
115+
path.segments.len()
116+
+ match path.kind {
117+
PathKind::Plain => 0,
118+
PathKind::Super(i) => i as usize,
119+
PathKind::Crate => 1,
120+
PathKind::Abs => 0,
121+
PathKind::DollarCrate(_) => 1,
122+
}
111123
}
112124

113125
fn find_importable_locations(

0 commit comments

Comments
 (0)