Skip to content

Commit

Permalink
Make GenericParams::lifetimes private
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jul 2, 2024
1 parent be1ea40 commit 966798b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/hir-def/src/child_by_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl ChildBySource for GenericDefId {

let generic_params = db.generic_params(*self);
let mut toc_idx_iter = generic_params.iter_type_or_consts().map(|(idx, _)| idx);
let lts_idx_iter = generic_params.lifetimes.iter().map(|(idx, _)| idx);
let lts_idx_iter = generic_params.iter_lt().map(|(idx, _)| idx);

// For traits the first type index is `Self`, skip it.
if let GenericDefId::TraitId(_) = *self {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub enum GenericParamDataRef<'a> {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct GenericParams {
type_or_consts: Arena<TypeOrConstParamData>,
pub lifetimes: Arena<LifetimeParamData>,
lifetimes: Arena<LifetimeParamData>,
where_predicates: Box<[WherePredicate]>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/item_tree/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl Printer<'_> {

w!(self, "<");
let mut first = true;
for (idx, lt) in params.lifetimes.iter() {
for (idx, lt) in params.iter_lt() {
if !first {
w!(self, ", ");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ impl Scope {
);
}
}
for (local_id, param) in params.lifetimes.iter() {
for (local_id, param) in params.iter_lt() {
let id = LifetimeParamId { parent, local_id };
acc.add(&param.name, ScopeDef::GenericParam(id.into()))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl HasChildSource<LocalLifetimeParamId> for GenericDefId {
db: &dyn DefDatabase,
) -> InFile<ArenaMap<LocalLifetimeParamId, Self::Value>> {
let generic_params = db.generic_params(*self);
let idx_iter = generic_params.lifetimes.iter().map(|(idx, _)| idx);
let idx_iter = generic_params.iter_lt().map(|(idx, _)| idx);

let (file_id, generic_params_list) = self.file_id_and_params_of(db);

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl Generics {
fn find_lifetime(&self, lifetime: LifetimeParamId) -> Option<usize> {
if lifetime.parent == self.def {
let idx = lifetime.local_id.into_raw().into_u32() as usize;
debug_assert!(idx <= self.params.lifetimes.len());
debug_assert!(idx <= self.params.len_lifetimes());
Some(self.params.len_type_or_consts() + idx)
} else {
debug_assert_eq!(self.parent_generics().map(|it| it.def), Some(lifetime.parent));
Expand Down
4 changes: 2 additions & 2 deletions crates/hir/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ fn write_generic_params(
f: &mut HirFormatter<'_>,
) -> Result<(), HirDisplayError> {
let params = f.db.generic_params(def);
if params.lifetimes.is_empty()
if params.iter_lt().next().is_none()
&& params.iter_type_or_consts().all(|it| it.1.const_param().is_none())
&& params
.iter_type_or_consts()
Expand All @@ -559,7 +559,7 @@ fn write_generic_params(
f.write_str(", ")
}
};
for (_, lifetime) in params.lifetimes.iter() {
for (_, lifetime) in params.iter_lt() {
delim(f)?;
write!(f, "{}", lifetime.name.display(f.db.upcast()))?;
}
Expand Down
10 changes: 4 additions & 6 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ impl Module {
}
let parent = impl_def.id.into();
let generic_params = db.generic_params(parent);
let lifetime_params = generic_params.lifetimes.iter().map(|(local_id, _)| {
let lifetime_params = generic_params.iter_lt().map(|(local_id, _)| {
GenericParamId::LifetimeParamId(LifetimeParamId { parent, local_id })
});
let type_params = generic_params
Expand Down Expand Up @@ -1540,8 +1540,7 @@ impl Adt {
resolver
.generic_params()
.and_then(|gp| {
gp.lifetimes
.iter()
gp.iter_lt()
// there should only be a single lifetime
// but `Arena` requires to use an iterator
.nth(0)
Expand Down Expand Up @@ -3141,8 +3140,7 @@ impl GenericDef {
pub fn lifetime_params(self, db: &dyn HirDatabase) -> Vec<LifetimeParam> {
let generics = db.generic_params(self.into());
generics
.lifetimes
.iter()
.iter_lt()
.map(|(local_id, _)| LifetimeParam {
id: LifetimeParamId { parent: self.into(), local_id },
})
Expand Down Expand Up @@ -3548,7 +3546,7 @@ pub struct LifetimeParam {
impl LifetimeParam {
pub fn name(self, db: &dyn HirDatabase) -> Name {
let params = db.generic_params(self.id.parent);
params.lifetimes[self.id.local_id].name.clone()
params[self.id.local_id].name.clone()
}

pub fn module(self, db: &dyn HirDatabase) -> Module {
Expand Down

0 comments on commit 966798b

Please sign in to comment.