mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Make GenericParams::where_predicates private
This commit is contained in:
parent
372e2d22e6
commit
be1ea4028b
5 changed files with 12 additions and 8 deletions
|
@ -161,7 +161,7 @@ pub enum GenericParamDataRef<'a> {
|
||||||
pub struct GenericParams {
|
pub struct GenericParams {
|
||||||
type_or_consts: Arena<TypeOrConstParamData>,
|
type_or_consts: Arena<TypeOrConstParamData>,
|
||||||
pub lifetimes: Arena<LifetimeParamData>,
|
pub lifetimes: Arena<LifetimeParamData>,
|
||||||
pub where_predicates: Box<[WherePredicate]>,
|
where_predicates: Box<[WherePredicate]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::Index<LocalTypeOrConstParamId> for GenericParams {
|
impl ops::Index<LocalTypeOrConstParamId> for GenericParams {
|
||||||
|
@ -228,6 +228,11 @@ impl GenericParams {
|
||||||
self.len() == 0
|
self.len() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn where_predicates(&self) -> std::slice::Iter<'_, WherePredicate> {
|
||||||
|
self.where_predicates.iter()
|
||||||
|
}
|
||||||
|
|
||||||
/// Iterator of type_or_consts field
|
/// Iterator of type_or_consts field
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_type_or_consts(
|
pub fn iter_type_or_consts(
|
||||||
|
|
|
@ -570,13 +570,13 @@ impl Printer<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_where_clause(&mut self, params: &GenericParams) -> bool {
|
fn print_where_clause(&mut self, params: &GenericParams) -> bool {
|
||||||
if params.where_predicates.is_empty() {
|
if params.where_predicates().next().is_none() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
w!(self, "\nwhere");
|
w!(self, "\nwhere");
|
||||||
self.indented(|this| {
|
self.indented(|this| {
|
||||||
for (i, pred) in params.where_predicates.iter().enumerate() {
|
for (i, pred) in params.where_predicates().enumerate() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
wln!(this, ",");
|
wln!(this, ",");
|
||||||
}
|
}
|
||||||
|
|
|
@ -596,7 +596,7 @@ impl Resolver {
|
||||||
Scope::GenericParams { params, def } => Some((params, def)),
|
Scope::GenericParams { params, def } => Some((params, def)),
|
||||||
_ => None,
|
_ => 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> {
|
pub fn generic_def(&self) -> Option<GenericDefId> {
|
||||||
|
|
|
@ -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 generic_params = db.generic_params(trait_.into());
|
||||||
let trait_self = generic_params.trait_self_param();
|
let trait_self = generic_params.trait_self_param();
|
||||||
generic_params
|
generic_params
|
||||||
.where_predicates
|
.where_predicates()
|
||||||
.iter()
|
|
||||||
.filter_map(|pred| match pred {
|
.filter_map(|pred| match pred {
|
||||||
WherePredicate::ForLifetime { target, bound, .. }
|
WherePredicate::ForLifetime { target, bound, .. }
|
||||||
| WherePredicate::TypeBound { target, bound } => {
|
| WherePredicate::TypeBound { target, bound } => {
|
||||||
|
|
|
@ -611,7 +611,7 @@ fn write_where_clause(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_disaplayable_predicates(params: &Interned<GenericParams>) -> bool {
|
fn has_disaplayable_predicates(params: &Interned<GenericParams>) -> bool {
|
||||||
params.where_predicates.iter().any(|pred| {
|
params.where_predicates().any(|pred| {
|
||||||
!matches!(
|
!matches!(
|
||||||
pred,
|
pred,
|
||||||
WherePredicate::TypeBound { target: WherePredicateTypeTarget::TypeOrConstParam(id), .. }
|
WherePredicate::TypeBound { target: WherePredicateTypeTarget::TypeOrConstParam(id), .. }
|
||||||
|
@ -652,7 +652,7 @@ fn write_where_predicates(
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut iter = params.where_predicates.iter().peekable();
|
let mut iter = params.where_predicates().peekable();
|
||||||
while let Some(pred) = iter.next() {
|
while let Some(pred) = iter.next() {
|
||||||
if matches!(pred, TypeBound { target, .. } if is_unnamed_type_target(params, target)) {
|
if matches!(pred, TypeBound { target, .. } if is_unnamed_type_target(params, target)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue