Properly handle turbofishes in qualifiers
This commit is contained in:
parent
d386481fac
commit
9482353fa8
5 changed files with 14 additions and 8 deletions
|
@ -44,6 +44,10 @@ pub enum ImportAlias {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModPath {
|
impl ModPath {
|
||||||
|
pub fn from_src_unhygienic(path: ast::Path) -> Option<ModPath> {
|
||||||
|
lower::lower_path(path, &Hygiene::new_unhygienic()).map(|it| it.mod_path)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
|
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
|
||||||
lower::lower_path(path, hygiene).map(|it| it.mod_path)
|
lower::lower_path(path, hygiene).map(|it| it.mod_path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
use PubMod3::PubStruct;
|
use PubMod1::PubStruct;
|
||||||
|
|
||||||
PubStruct
|
PubStruct
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
PubMod3::PubStruct
|
PubMod1::PubStruct
|
||||||
|
|
||||||
pub mod PubMod1 {
|
pub mod PubMod1 {
|
||||||
pub struct PubStruct;
|
pub struct PubStruct;
|
||||||
|
|
|
@ -669,8 +669,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
|
|
||||||
fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED
|
fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED
|
||||||
|
ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub struct PathImportCandidate {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Qualifier {
|
pub enum Qualifier {
|
||||||
Absent,
|
Absent,
|
||||||
FirstSegmentUnresolved(ast::PathSegment, ast::Path),
|
FirstSegmentUnresolved(ast::NameRef, ModPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -297,8 +297,7 @@ fn path_applicable_imports(
|
||||||
Qualifier::FirstSegmentUnresolved(first_segment, qualifier) => (first_segment, qualifier),
|
Qualifier::FirstSegmentUnresolved(first_segment, qualifier) => (first_segment, qualifier),
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO kb need to remove turbofish from the qualifier, maybe use the segments instead?
|
// TODO kb zz.syntax().ast_node() <- two options are now proposed despite the trait being imported
|
||||||
// TODO kb sorting is changed now, return back?
|
|
||||||
let unresolved_qualifier_string = unresolved_qualifier.to_string();
|
let unresolved_qualifier_string = unresolved_qualifier.to_string();
|
||||||
let unresolved_first_segment_string = unresolved_first_segment.to_string();
|
let unresolved_first_segment_string = unresolved_first_segment.to_string();
|
||||||
|
|
||||||
|
@ -525,12 +524,15 @@ fn path_import_candidate(
|
||||||
Some(qualifier) => match sema.resolve_path(&qualifier) {
|
Some(qualifier) => match sema.resolve_path(&qualifier) {
|
||||||
None => {
|
None => {
|
||||||
let qualifier_start =
|
let qualifier_start =
|
||||||
qualifier.syntax().descendants().find_map(ast::PathSegment::cast)?;
|
qualifier.syntax().descendants().find_map(ast::NameRef::cast)?;
|
||||||
let qualifier_start_path =
|
let qualifier_start_path =
|
||||||
qualifier_start.syntax().ancestors().find_map(ast::Path::cast)?;
|
qualifier_start.syntax().ancestors().find_map(ast::Path::cast)?;
|
||||||
if sema.resolve_path(&qualifier_start_path).is_none() {
|
if sema.resolve_path(&qualifier_start_path).is_none() {
|
||||||
ImportCandidate::Path(PathImportCandidate {
|
ImportCandidate::Path(PathImportCandidate {
|
||||||
qualifier: Qualifier::FirstSegmentUnresolved(qualifier_start, qualifier),
|
qualifier: Qualifier::FirstSegmentUnresolved(
|
||||||
|
qualifier_start,
|
||||||
|
ModPath::from_src_unhygienic(qualifier)?,
|
||||||
|
),
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue