Make GenericParams::where_predicates private

This commit is contained in:
Lukas Wirth 2024-07-02 11:27:56 +02:00
parent 372e2d22e6
commit be1ea4028b
5 changed files with 12 additions and 8 deletions

View file

@ -161,7 +161,7 @@ pub enum GenericParamDataRef<'a> {
pub struct GenericParams {
type_or_consts: Arena<TypeOrConstParamData>,
pub lifetimes: Arena<LifetimeParamData>,
pub where_predicates: Box<[WherePredicate]>,
where_predicates: Box<[WherePredicate]>,
}
impl ops::Index<LocalTypeOrConstParamId> for GenericParams {
@ -228,6 +228,11 @@ impl GenericParams {
self.len() == 0
}
#[inline]
pub fn where_predicates(&self) -> std::slice::Iter<'_, WherePredicate> {
self.where_predicates.iter()
}
/// Iterator of type_or_consts field
#[inline]
pub fn iter_type_or_consts(

View file

@ -570,13 +570,13 @@ impl Printer<'_> {
}
fn print_where_clause(&mut self, params: &GenericParams) -> bool {
if params.where_predicates.is_empty() {
if params.where_predicates().next().is_none() {
return false;
}
w!(self, "\nwhere");
self.indented(|this| {
for (i, pred) in params.where_predicates.iter().enumerate() {
for (i, pred) in params.where_predicates().enumerate() {
if i != 0 {
wln!(this, ",");
}

View file

@ -596,7 +596,7 @@ impl Resolver {
Scope::GenericParams { params, def } => Some((params, def)),
_ => None,
})
.flat_map(|(params, def)| params.where_predicates.iter().zip(iter::repeat(def)))
.flat_map(|(params, def)| params.where_predicates().zip(iter::repeat(def)))
}
pub fn generic_def(&self) -> Option<GenericDefId> {

View file

@ -157,8 +157,7 @@ fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId, cb: impl FnMut(Tra
let generic_params = db.generic_params(trait_.into());
let trait_self = generic_params.trait_self_param();
generic_params
.where_predicates
.iter()
.where_predicates()
.filter_map(|pred| match pred {
WherePredicate::ForLifetime { target, bound, .. }
| WherePredicate::TypeBound { target, bound } => {

View file

@ -611,7 +611,7 @@ fn write_where_clause(
}
fn has_disaplayable_predicates(params: &Interned<GenericParams>) -> bool {
params.where_predicates.iter().any(|pred| {
params.where_predicates().any(|pred| {
!matches!(
pred,
WherePredicate::TypeBound { target: WherePredicateTypeTarget::TypeOrConstParam(id), .. }
@ -652,7 +652,7 @@ fn write_where_predicates(
_ => false,
};
let mut iter = params.where_predicates.iter().peekable();
let mut iter = params.where_predicates().peekable();
while let Some(pred) = iter.next() {
if matches!(pred, TypeBound { target, .. } if is_unnamed_type_target(params, target)) {
continue;