mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
internal: Simplify
This commit is contained in:
parent
312ac83caf
commit
2642f64570
6 changed files with 75 additions and 94 deletions
|
@ -12,13 +12,12 @@ use hir_def::{
|
|||
WherePredicateTypeTarget,
|
||||
},
|
||||
intern::Interned,
|
||||
path::Path,
|
||||
resolver::{HasResolver, TypeNs},
|
||||
type_ref::{TraitBoundModifier, TypeRef},
|
||||
ConstParamId, FunctionId, GenericDefId, ItemContainerId, Lookup, TraitId, TypeAliasId,
|
||||
TypeOrConstParamId, TypeParamId,
|
||||
};
|
||||
use hir_expand::name::{known, name, Name};
|
||||
use hir_expand::name::{known, Name};
|
||||
use itertools::Either;
|
||||
use rustc_hash::FxHashSet;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
@ -53,25 +52,25 @@ fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> SmallVec<[Trait
|
|||
.iter()
|
||||
.filter_map(|pred| match pred {
|
||||
WherePredicate::ForLifetime { target, bound, .. }
|
||||
| WherePredicate::TypeBound { target, bound } => match target {
|
||||
WherePredicateTypeTarget::TypeRef(type_ref) => match &**type_ref {
|
||||
TypeRef::Path(p) if p == &Path::from(name![Self]) => bound.as_path(),
|
||||
_ => None,
|
||||
},
|
||||
WherePredicateTypeTarget::TypeOrConstParam(local_id)
|
||||
if Some(*local_id) == trait_self =>
|
||||
{
|
||||
bound.as_path()
|
||||
| WherePredicate::TypeBound { target, bound } => {
|
||||
let is_trait = match target {
|
||||
WherePredicateTypeTarget::TypeRef(type_ref) => match &**type_ref {
|
||||
TypeRef::Path(p) => p.is_self_type(),
|
||||
_ => false,
|
||||
},
|
||||
WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
|
||||
Some(*local_id) == trait_self
|
||||
}
|
||||
};
|
||||
match is_trait {
|
||||
true => bound.as_path(),
|
||||
false => None,
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
WherePredicate::Lifetime { .. } => None,
|
||||
})
|
||||
.filter_map(|(path, bound_modifier)| match bound_modifier {
|
||||
TraitBoundModifier::None => Some(path),
|
||||
TraitBoundModifier::Maybe => None,
|
||||
})
|
||||
.filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path.mod_path()) {
|
||||
.filter(|(_, bound_modifier)| matches!(bound_modifier, TraitBoundModifier::None))
|
||||
.filter_map(|(path, _)| match resolver.resolve_path_in_type_ns_fully(db, path.mod_path()) {
|
||||
Some(TypeNs::TraitId(t)) => Some(t),
|
||||
_ => None,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue