diff --git a/crates/hir-def/src/generics.rs b/crates/hir-def/src/generics.rs index 8570bac9a9..fe9004fcc6 100644 --- a/crates/hir-def/src/generics.rs +++ b/crates/hir-def/src/generics.rs @@ -161,7 +161,7 @@ pub enum GenericParamDataRef<'a> { pub struct GenericParams { type_or_consts: Arena, pub lifetimes: Arena, - pub where_predicates: Box<[WherePredicate]>, + where_predicates: Box<[WherePredicate]>, } impl ops::Index 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( diff --git a/crates/hir-def/src/item_tree/pretty.rs b/crates/hir-def/src/item_tree/pretty.rs index 59031824e1..ad260df80f 100644 --- a/crates/hir-def/src/item_tree/pretty.rs +++ b/crates/hir-def/src/item_tree/pretty.rs @@ -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, ","); } diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs index c573411309..a8cedd7421 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -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 { diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs index 969999cdb8..738e842146 100644 --- a/crates/hir-ty/src/utils.rs +++ b/crates/hir-ty/src/utils.rs @@ -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 } => { diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 6c2cb55cc4..05047450af 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -611,7 +611,7 @@ fn write_where_clause( } fn has_disaplayable_predicates(params: &Interned) -> 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;