7297: Propose trait associated items and autoimport traits on completion r=matklad a=SomeoneToIgnore

![trait_imports](https://user-images.githubusercontent.com/2690773/104819998-6faeb480-583a-11eb-8b45-b7351b51b90e.gif)

Closes #7248

7338: Parse `impl const Trait` r=Veykril a=Veykril

Closes #7313

bors r+

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-01-18 19:40:11 +00:00 committed by GitHub
commit 342bf41022
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 885 additions and 288 deletions

View file

@ -438,10 +438,10 @@ fn get_symbol_fragment(db: &dyn HirDatabase, field_or_assoc: &FieldOrAssocItem)
FieldOrAssocItem::Field(field) => format!("#structfield.{}", field.name(db)),
FieldOrAssocItem::AssocItem(assoc) => match assoc {
AssocItem::Function(function) => {
let is_trait_method = matches!(
function.as_assoc_item(db).map(|assoc| assoc.container(db)),
Some(AssocItemContainer::Trait(..))
);
let is_trait_method = function
.as_assoc_item(db)
.and_then(|assoc| assoc.containing_trait(db))
.is_some();
// This distinction may get more complicated when specialization is available.
// Rustdoc makes this decision based on whether a method 'has defaultness'.
// Currently this is only the case for provided trait methods.

View file

@ -478,6 +478,7 @@ impl Analysis {
position: FilePosition,
full_import_path: &str,
imported_name: String,
import_for_trait_assoc_item: bool,
) -> Cancelable<Vec<TextEdit>> {
Ok(self
.with_db(|db| {
@ -487,6 +488,7 @@ impl Analysis {
position,
full_import_path,
imported_name,
import_for_trait_assoc_item,
)
})?
.unwrap_or_default())