mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Deduplicate some code
This commit is contained in:
parent
bb0de88f24
commit
2ebf0c87c2
22 changed files with 299 additions and 234 deletions
|
@ -668,7 +668,7 @@ fn get_assoc_item_fragment(db: &dyn HirDatabase, assoc_item: hir::AssocItem) ->
|
|||
Some(match assoc_item {
|
||||
AssocItem::Function(function) => {
|
||||
let is_trait_method =
|
||||
function.as_assoc_item(db).and_then(|assoc| assoc.containing_trait(db)).is_some();
|
||||
function.as_assoc_item(db).and_then(|assoc| assoc.container_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.
|
||||
|
|
|
@ -61,7 +61,7 @@ pub(crate) fn goto_declaration(
|
|||
_ => None,
|
||||
}?;
|
||||
|
||||
let trait_ = assoc.containing_trait_impl(db)?;
|
||||
let trait_ = assoc.implemented_trait(db)?;
|
||||
let name = Some(assoc.name(db)?);
|
||||
let item = trait_.items(db).into_iter().find(|it| it.name(db) == name)?;
|
||||
item.try_to_nav(db)
|
||||
|
|
|
@ -182,11 +182,7 @@ fn try_filter_trait_item_definition(
|
|||
match assoc {
|
||||
AssocItem::Function(..) => None,
|
||||
AssocItem::Const(..) | AssocItem::TypeAlias(..) => {
|
||||
let imp = match assoc.container(db) {
|
||||
hir::AssocItemContainer::Impl(imp) => imp,
|
||||
_ => return None,
|
||||
};
|
||||
let trait_ = imp.trait_(db)?;
|
||||
let trait_ = assoc.implemented_trait(db)?;
|
||||
let name = def.name(db)?;
|
||||
let discri_value = discriminant(&assoc);
|
||||
trait_
|
||||
|
|
|
@ -60,13 +60,13 @@ pub(crate) fn goto_implementation(
|
|||
Definition::Function(f) => {
|
||||
let assoc = f.as_assoc_item(sema.db)?;
|
||||
let name = assoc.name(sema.db)?;
|
||||
let trait_ = assoc.containing_trait_or_trait_impl(sema.db)?;
|
||||
let trait_ = assoc.container_or_implemented_trait(sema.db)?;
|
||||
impls_for_trait_item(&sema, trait_, name)
|
||||
}
|
||||
Definition::Const(c) => {
|
||||
let assoc = c.as_assoc_item(sema.db)?;
|
||||
let name = assoc.name(sema.db)?;
|
||||
let trait_ = assoc.containing_trait_or_trait_impl(sema.db)?;
|
||||
let trait_ = assoc.container_or_implemented_trait(sema.db)?;
|
||||
impls_for_trait_item(&sema, trait_, name)
|
||||
}
|
||||
_ => return None,
|
||||
|
|
|
@ -442,8 +442,7 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
|
|||
.for_each(|name| format_to!(path, "{}::", name.display(db)));
|
||||
// This probably belongs to canonical_path?
|
||||
if let Some(assoc_item) = def.as_assoc_item(db) {
|
||||
if let hir::AssocItemContainer::Impl(imp) = assoc_item.container(db) {
|
||||
let ty = imp.self_ty(db);
|
||||
if let Some(ty) = assoc_item.implementing_ty(db) {
|
||||
if let Some(adt) = ty.as_adt() {
|
||||
let name = adt.name(db);
|
||||
let mut ty_args = ty.generic_parameters(db).peekable();
|
||||
|
|
|
@ -559,7 +559,7 @@ fn highlight_method_call(
|
|||
}
|
||||
if func
|
||||
.as_assoc_item(sema.db)
|
||||
.and_then(|it| it.containing_trait_or_trait_impl(sema.db))
|
||||
.and_then(|it| it.container_or_implemented_trait(sema.db))
|
||||
.is_some()
|
||||
{
|
||||
h |= HlMod::Trait;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue