Skip to content

Commit

Permalink
Returns the old value for la_arena::ArenaMap::insert
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Aug 6, 2022
1 parent 1a94193 commit 326ffee
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
if let GenericDefId::TraitId(id) = *self {
let trait_ref = id.lookup(db).source(db).value;
let idx = idx_iter.next().unwrap();
params.insert(idx, Either::Right(trait_ref))
params.insert(idx, Either::Right(trait_ref));
}

if let Some(generic_params_list) = generic_params_list {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub(crate) fn field_visibilities_query(
let resolver = variant_id.module(db).resolver(db);
let mut res = ArenaMap::default();
for (field_id, field_data) in var_data.fields().iter() {
res.insert(field_id, field_data.visibility.resolve(db, &resolver))
res.insert(field_id, field_data.visibility.resolve(db, &resolver));
}
Arc::new(res)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ pub(crate) fn field_types_query(
let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(ParamLoweringMode::Variable);
for (field_id, field_data) in var_data.fields().iter() {
res.insert(field_id, make_binders(db, &generics, ctx.lower_ty(&field_data.type_ref)))
res.insert(field_id, make_binders(db, &generics, ctx.lower_ty(&field_data.type_ref)));
}
Arc::new(res)
}
Expand Down
7 changes: 5 additions & 2 deletions lib/la-arena/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ impl<T, V> ArenaMap<Idx<T>, V> {
}

/// Inserts a value associated with a given arena index into the map.
pub fn insert(&mut self, idx: Idx<T>, t: V) {
///
/// If the map did not have this index present, None is returned.
/// Otherwise, the value is updated, and the old value is returned.
pub fn insert(&mut self, idx: Idx<T>, t: V) -> Option<V> {
let idx = Self::to_idx(idx);

self.v.resize_with((idx + 1).max(self.v.len()), || None);
self.v[idx] = Some(t);
self.v[idx].replace(t)
}

/// Returns a reference to the value associated with the provided index
Expand Down

0 comments on commit 326ffee

Please sign in to comment.