Skip to content

Commit

Permalink
Auto merge of rust-lang#12509 - Veykril:ty-utils, r=Veykril
Browse files Browse the repository at this point in the history
internal: Remove `Generics::type_iter` in favor of `Generics::iter`
  • Loading branch information
bors committed Jun 12, 2022
2 parents eacade2 + 7a0ab13 commit d513f65
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
8 changes: 0 additions & 8 deletions crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ pub enum WherePredicateTypeTarget {
}

impl GenericParams {
// FIXME: almost every usecase of this function is wrong. every one should check
// const generics
pub fn type_iter<'a>(
&'a self,
) -> impl Iterator<Item = (Idx<TypeOrConstParamData>, &TypeParamData)> {
self.type_or_consts.iter().filter_map(|x| x.1.type_param().map(|y| (x.0, y)))
}

/// Iterator of type_or_consts field
pub fn iter<'a>(
&'a self,
Expand Down
8 changes: 6 additions & 2 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,13 @@ impl<'a> TyLoweringContext<'a> {
if let Some(def) = self.resolver.generic_def() {
let generics = generics(self.db.upcast(), def);
let param = generics
.type_iter()
.iter()
.filter(|(_, data)| {
data.provenance == TypeParamProvenance::ArgumentImplTrait
matches!(
data,
TypeOrConstParamData::TypeParamData(data)
if data.provenance == TypeParamProvenance::ArgumentImplTrait
)
})
.nth(idx as usize)
.map_or(TyKind::Error, |(id, _)| {
Expand Down
21 changes: 1 addition & 20 deletions crates/hir-ty/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chalk_ir::{fold::Shift, BoundVar, DebruijnIndex};
use hir_def::{
db::DefDatabase,
generics::{
GenericParams, TypeOrConstParamData, TypeParamData, TypeParamProvenance, WherePredicate,
GenericParams, TypeOrConstParamData, TypeParamProvenance, WherePredicate,
WherePredicateTypeTarget,
},
intern::Interned,
Expand Down Expand Up @@ -204,25 +204,6 @@ pub(crate) struct Generics {
}

impl Generics {
// FIXME: we should drop this and handle const and type generics at the same time
pub(crate) fn type_iter<'a>(
&'a self,
) -> impl Iterator<Item = (TypeOrConstParamId, &'a TypeParamData)> + 'a {
self.parent_generics
.as_ref()
.into_iter()
.flat_map(|it| {
it.params
.type_iter()
.map(move |(local_id, p)| (TypeOrConstParamId { parent: it.def, local_id }, p))
})
.chain(
self.params.type_iter().map(move |(local_id, p)| {
(TypeOrConstParamId { parent: self.def, local_id }, p)
}),
)
}

pub(crate) fn iter_id<'a>(
&'a self,
) -> impl Iterator<Item = Either<TypeParamId, ConstParamId>> + 'a {
Expand Down

0 comments on commit d513f65

Please sign in to comment.