mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-13 17:35:21 +00:00
Change direct_super_traits to use generic_predicates_for_param_ns
This commit is contained in:
parent
17b94c41b1
commit
aa890b49ff
4 changed files with 50 additions and 25 deletions
|
|
@ -4,10 +4,7 @@
|
||||||
use std::{cell::LazyCell, iter};
|
use std::{cell::LazyCell, iter};
|
||||||
|
|
||||||
use base_db::Crate;
|
use base_db::Crate;
|
||||||
use chalk_ir::{
|
use chalk_ir::{DebruijnIndex, fold::FallibleTypeFolder};
|
||||||
DebruijnIndex,
|
|
||||||
fold::{FallibleTypeFolder, Shift},
|
|
||||||
};
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
EnumId, EnumVariantId, FunctionId, Lookup, TraitId, TypeAliasId, TypeOrConstParamId,
|
EnumId, EnumVariantId, FunctionId, Lookup, TraitId, TypeAliasId, TypeOrConstParamId,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
|
|
@ -20,6 +17,7 @@ use hir_expand::name::Name;
|
||||||
use intern::sym;
|
use intern::sym;
|
||||||
use rustc_abi::TargetDataLayout;
|
use rustc_abi::TargetDataLayout;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use rustc_type_ir::inherent::{IntoKind, SliceLike};
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use span::Edition;
|
use span::Edition;
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
|
|
@ -31,6 +29,11 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
layout::{Layout, TagEncoding},
|
layout::{Layout, TagEncoding},
|
||||||
mir::pad16,
|
mir::pad16,
|
||||||
|
next_solver::{
|
||||||
|
DbInterner,
|
||||||
|
mapping::{ChalkToNextSolver, convert_args_for_result},
|
||||||
|
},
|
||||||
|
to_chalk_trait_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn fn_traits(db: &dyn DefDatabase, krate: Crate) -> impl Iterator<Item = TraitId> + '_ {
|
pub(crate) fn fn_traits(db: &dyn DefDatabase, krate: Crate) -> impl Iterator<Item = TraitId> + '_ {
|
||||||
|
|
@ -191,25 +194,37 @@ fn direct_super_traits_cb(db: &dyn DefDatabase, trait_: TraitId, cb: impl FnMut(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef, cb: impl FnMut(TraitRef)) {
|
fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef, cb: impl FnMut(TraitRef)) {
|
||||||
|
let interner = DbInterner::new_with(db, None, None);
|
||||||
let generic_params = db.generic_params(trait_ref.hir_trait_id().into());
|
let generic_params = db.generic_params(trait_ref.hir_trait_id().into());
|
||||||
let trait_self = match generic_params.trait_self_param() {
|
let trait_self = match generic_params.trait_self_param() {
|
||||||
Some(p) => TypeOrConstParamId { parent: trait_ref.hir_trait_id().into(), local_id: p },
|
Some(p) => TypeOrConstParamId { parent: trait_ref.hir_trait_id().into(), local_id: p },
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
db.generic_predicates_for_param(trait_self.parent, trait_self, None)
|
let trait_ref_args: crate::next_solver::GenericArgs<'_> =
|
||||||
|
trait_ref.substitution.to_nextsolver(interner);
|
||||||
|
db.generic_predicates_for_param_ns(trait_self.parent, trait_self, None)
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|pred| {
|
.filter_map(|pred| {
|
||||||
pred.as_ref().filter_map(|pred| match pred.skip_binders() {
|
let pred = pred.kind();
|
||||||
// FIXME: how to correctly handle higher-ranked bounds here?
|
// FIXME: how to correctly handle higher-ranked bounds here?
|
||||||
WhereClause::Implemented(tr) => Some(
|
let pred = pred.no_bound_vars().expect("FIXME unexpected higher-ranked trait bound");
|
||||||
tr.clone()
|
match pred {
|
||||||
.shifted_out_to(Interner, DebruijnIndex::ONE)
|
rustc_type_ir::ClauseKind::Trait(t) => {
|
||||||
.expect("FIXME unexpected higher-ranked trait bound"),
|
let t =
|
||||||
),
|
rustc_type_ir::EarlyBinder::bind(t).instantiate(interner, trait_ref_args);
|
||||||
|
let trait_id = match t.def_id() {
|
||||||
|
crate::next_solver::SolverDefId::TraitId(id) => to_chalk_trait_id(id),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let substitution =
|
||||||
|
convert_args_for_result(interner, t.trait_ref.args.as_slice());
|
||||||
|
let tr = chalk_ir::TraitRef { trait_id, substitution };
|
||||||
|
Some(tr)
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
.map(|pred| pred.substitute(Interner, &trait_ref.substitution))
|
|
||||||
.for_each(cb);
|
.for_each(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,8 @@ use hir_ty::{
|
||||||
method_resolution,
|
method_resolution,
|
||||||
mir::{MutBorrowKind, interpret_mir},
|
mir::{MutBorrowKind, interpret_mir},
|
||||||
next_solver::{
|
next_solver::{
|
||||||
DbInterner, GenericArgs, SolverDefId, infer::InferCtxt, mapping::ChalkToNextSolver,
|
ClauseKind, DbInterner, GenericArgs, SolverDefId, infer::InferCtxt,
|
||||||
|
mapping::ChalkToNextSolver,
|
||||||
},
|
},
|
||||||
primitive::UintTy,
|
primitive::UintTy,
|
||||||
traits::FnTrait,
|
traits::FnTrait,
|
||||||
|
|
@ -114,6 +115,7 @@ pub use crate::{
|
||||||
VisibleTraits,
|
VisibleTraits,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use rustc_type_ir::inherent::IntoKind;
|
||||||
|
|
||||||
// Be careful with these re-exports.
|
// Be careful with these re-exports.
|
||||||
//
|
//
|
||||||
|
|
@ -4245,11 +4247,15 @@ impl TypeParam {
|
||||||
/// parameter, not additional bounds that might be added e.g. by a method if
|
/// parameter, not additional bounds that might be added e.g. by a method if
|
||||||
/// the parameter comes from an impl!
|
/// the parameter comes from an impl!
|
||||||
pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
|
pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
|
||||||
db.generic_predicates_for_param(self.id.parent(), self.id.into(), None)
|
db.generic_predicates_for_param_ns(self.id.parent(), self.id.into(), None)
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|pred| match &pred.skip_binders().skip_binders() {
|
.filter_map(|pred| match &pred.kind().skip_binder() {
|
||||||
hir_ty::WhereClause::Implemented(trait_ref) => {
|
ClauseKind::Trait(trait_ref) => {
|
||||||
Some(Trait::from(trait_ref.hir_trait_id()))
|
let trait_ = match trait_ref.def_id() {
|
||||||
|
SolverDefId::TraitId(t) => t,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
Some(Trait::from(trait_))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -581,11 +581,13 @@ fn goto_type_action_for_def(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(generic_def) = GenericDef::try_from(def) {
|
salsa::attach(db, || {
|
||||||
generic_def.type_or_const_params(db).into_iter().for_each(|it| {
|
if let Ok(generic_def) = GenericDef::try_from(def) {
|
||||||
walk_and_push_ty(db, &it.ty(db), &mut push_new_def);
|
generic_def.type_or_const_params(db).into_iter().for_each(|it| {
|
||||||
});
|
walk_and_push_ty(db, &it.ty(db), &mut push_new_def);
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let ty = match def {
|
let ty = match def {
|
||||||
Definition::Local(it) => Some(it.ty(db)),
|
Definition::Local(it) => Some(it.ty(db)),
|
||||||
|
|
|
||||||
|
|
@ -674,7 +674,9 @@ impl Analysis {
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancellable<Option<Vec<HighlightedRange>>> {
|
) -> Cancellable<Option<Vec<HighlightedRange>>> {
|
||||||
self.with_db(|db| {
|
self.with_db(|db| {
|
||||||
highlight_related::highlight_related(&Semantics::new(db), config, position)
|
salsa::attach(db, || {
|
||||||
|
highlight_related::highlight_related(&Semantics::new(db), config, position)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue