Skip to content

Commit f6e70e7

Browse files
bors[bot]matklad
andauthored
Merge #4514
4514: find_path cleanups r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 5c1c23e + dce31ef commit f6e70e7

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

crates/ra_hir_def/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
112112
#[salsa::invoke(Documentation::documentation_query)]
113113
fn documentation(&self, def: AttrDefId) -> Option<Documentation>;
114114

115-
#[salsa::invoke(find_path::importable_locations_in_crate)]
115+
#[salsa::invoke(find_path::importable_locations_of_query)]
116116
fn importable_locations_of(
117117
&self,
118118
item: ItemInNs,

crates/ra_hir_def/src/find_path.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
//! An algorithm to find a path to refer to a certain item.
22
3+
use std::sync::Arc;
4+
5+
use hir_expand::name::{known, AsName, Name};
6+
use ra_prof::profile;
7+
use test_utils::tested_by;
8+
39
use crate::{
410
db::DefDatabase,
511
item_scope::ItemInNs,
612
path::{ModPath, PathKind},
713
visibility::Visibility,
814
CrateId, ModuleDefId, ModuleId,
915
};
10-
use hir_expand::name::{known, AsName, Name};
11-
use std::sync::Arc;
12-
use test_utils::tested_by;
16+
17+
// FIXME: handle local items
18+
19+
/// Find a path that can be used to refer to a certain item. This can depend on
20+
/// *from where* you're referring to the item, hence the `from` parameter.
21+
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
22+
let _p = profile("find_path");
23+
find_path_inner(db, item, from, MAX_PATH_LEN)
24+
}
1325

1426
const MAX_PATH_LEN: usize = 15;
1527

1628
impl ModPath {
1729
fn starts_with_std(&self) -> bool {
18-
self.segments.first().filter(|&first_segment| first_segment == &known::std).is_some()
30+
self.segments.first() == Some(&known::std)
1931
}
2032

2133
// When std library is present, paths starting with `std::`
2234
// should be preferred over paths starting with `core::` and `alloc::`
2335
fn can_start_with_std(&self) -> bool {
24-
self.segments
25-
.first()
26-
.filter(|&first_segment| {
27-
first_segment == &known::alloc || first_segment == &known::core
28-
})
29-
.is_some()
36+
let first_segment = self.segments.first();
37+
first_segment == Some(&known::alloc) || first_segment == Some(&known::core)
3038
}
3139

3240
fn len(&self) -> usize {
@@ -41,15 +49,6 @@ impl ModPath {
4149
}
4250
}
4351

44-
// FIXME: handle local items
45-
46-
/// Find a path that can be used to refer to a certain item. This can depend on
47-
/// *from where* you're referring to the item, hence the `from` parameter.
48-
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
49-
let _p = ra_prof::profile("find_path");
50-
find_path_inner(db, item, from, MAX_PATH_LEN)
51-
}
52-
5352
fn find_path_inner(
5453
db: &dyn DefDatabase,
5554
item: ItemInNs,
@@ -215,11 +214,12 @@ fn find_importable_locations(
215214
///
216215
/// Note that the crate doesn't need to be the one in which the item is defined;
217216
/// it might be re-exported in other crates.
218-
pub(crate) fn importable_locations_in_crate(
217+
pub(crate) fn importable_locations_of_query(
219218
db: &dyn DefDatabase,
220219
item: ItemInNs,
221220
krate: CrateId,
222221
) -> Arc<[(ModuleId, Name, Visibility)]> {
222+
let _p = profile("importable_locations_of_query");
223223
let def_map = db.crate_def_map(krate);
224224
let mut result = Vec::new();
225225
for (local_id, data) in def_map.modules.iter() {

0 commit comments

Comments
 (0)