Skip to content

Commit 9482353

Browse files
Properly handle turbofishes in qualifiers
1 parent d386481 commit 9482353

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

crates/hir_def/src/path.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ pub enum ImportAlias {
4444
}
4545

4646
impl ModPath {
47+
pub fn from_src_unhygienic(path: ast::Path) -> Option<ModPath> {
48+
lower::lower_path(path, &Hygiene::new_unhygienic()).map(|it| it.mod_path)
49+
}
50+
4751
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
4852
lower::lower_path(path, hygiene).map(|it| it.mod_path)
4953
}

crates/ide_assists/src/handlers/auto_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ mod tests {
242242
}
243243
",
244244
r"
245-
use PubMod3::PubStruct;
245+
use PubMod1::PubStruct;
246246
247247
PubStruct
248248

crates/ide_assists/src/handlers/qualify_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ mod tests {
313313
}
314314
",
315315
r"
316-
PubMod3::PubStruct
316+
PubMod1::PubStruct
317317
318318
pub mod PubMod1 {
319319
pub struct PubStruct;

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ fn main() {
669669
}
670670
"#,
671671
expect![[r#"
672-
ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
673672
fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED
673+
ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
674674
"#]],
675675
);
676676
}

crates/ide_db/src/helpers/import_assets.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct PathImportCandidate {
4343
#[derive(Debug)]
4444
pub enum Qualifier {
4545
Absent,
46-
FirstSegmentUnresolved(ast::PathSegment, ast::Path),
46+
FirstSegmentUnresolved(ast::NameRef, ModPath),
4747
}
4848

4949
#[derive(Debug)]
@@ -297,8 +297,7 @@ fn path_applicable_imports(
297297
Qualifier::FirstSegmentUnresolved(first_segment, qualifier) => (first_segment, qualifier),
298298
};
299299

300-
// TODO kb need to remove turbofish from the qualifier, maybe use the segments instead?
301-
// TODO kb sorting is changed now, return back?
300+
// TODO kb zz.syntax().ast_node() <- two options are now proposed despite the trait being imported
302301
let unresolved_qualifier_string = unresolved_qualifier.to_string();
303302
let unresolved_first_segment_string = unresolved_first_segment.to_string();
304303

@@ -525,12 +524,15 @@ fn path_import_candidate(
525524
Some(qualifier) => match sema.resolve_path(&qualifier) {
526525
None => {
527526
let qualifier_start =
528-
qualifier.syntax().descendants().find_map(ast::PathSegment::cast)?;
527+
qualifier.syntax().descendants().find_map(ast::NameRef::cast)?;
529528
let qualifier_start_path =
530529
qualifier_start.syntax().ancestors().find_map(ast::Path::cast)?;
531530
if sema.resolve_path(&qualifier_start_path).is_none() {
532531
ImportCandidate::Path(PathImportCandidate {
533-
qualifier: Qualifier::FirstSegmentUnresolved(qualifier_start, qualifier),
532+
qualifier: Qualifier::FirstSegmentUnresolved(
533+
qualifier_start,
534+
ModPath::from_src_unhygienic(qualifier)?,
535+
),
534536
name,
535537
})
536538
} else {

0 commit comments

Comments
 (0)