8095: Fix associated items not being appended to paths in import_assets r=SomeoneToIgnore a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-03-18 21:40:12 +00:00 committed by GitHub
commit 86878443b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 3 deletions

View File

@ -208,8 +208,10 @@ fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
format!("Qualify as `{}`", import.import_path) format!("Qualify as `{}`", import.import_path)
} }
} }
ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", import.import_path), ImportCandidate::TraitAssocItem(_) => {
ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", import.import_path), format!("Qualify with `{}`", import.import_path)
}
ImportCandidate::TraitMethod(_) => format!("Qualify with `{}`", import.import_path),
} }
} }
@ -543,6 +545,37 @@ fn main() {
); );
} }
#[test]
fn associated_struct_const_unqualified() {
check_assist(
qualify_path,
r"
mod test_mod {
pub struct TestStruct {}
impl TestStruct {
const TEST_CONST: u8 = 42;
}
}
fn main() {
TEST_CONST$0
}
",
r"
mod test_mod {
pub struct TestStruct {}
impl TestStruct {
const TEST_CONST: u8 = 42;
}
}
fn main() {
test_mod::TestStruct::TEST_CONST
}
",
);
}
#[test] #[test]
fn associated_trait_function() { fn associated_trait_function() {
check_assist( check_assist(

View File

@ -304,7 +304,11 @@ fn path_applicable_imports(
return items_with_candidate_name return items_with_candidate_name
.into_iter() .into_iter()
.filter_map(|item| { .filter_map(|item| {
Some(LocatedImport::new(mod_path(item)?, item, item, mod_path(item))) let mut mod_path = mod_path(item)?;
if let Some(assoc_item) = item_as_assoc(db, item) {
mod_path.push_segment(assoc_item.name(db)?);
}
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
}) })
.collect(); .collect();
} }