Skip to content

Commit 326ffee

Browse files
committed
Returns the old value for la_arena::ArenaMap::insert
1 parent 1a94193 commit 326ffee

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

crates/hir-def/src/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
451451
if let GenericDefId::TraitId(id) = *self {
452452
let trait_ref = id.lookup(db).source(db).value;
453453
let idx = idx_iter.next().unwrap();
454-
params.insert(idx, Either::Right(trait_ref))
454+
params.insert(idx, Either::Right(trait_ref));
455455
}
456456

457457
if let Some(generic_params_list) = generic_params_list {

crates/hir-def/src/visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub(crate) fn field_visibilities_query(
224224
let resolver = variant_id.module(db).resolver(db);
225225
let mut res = ArenaMap::default();
226226
for (field_id, field_data) in var_data.fields().iter() {
227-
res.insert(field_id, field_data.visibility.resolve(db, &resolver))
227+
res.insert(field_id, field_data.visibility.resolve(db, &resolver));
228228
}
229229
Arc::new(res)
230230
}

crates/hir-ty/src/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ pub(crate) fn field_types_query(
11261126
let ctx =
11271127
TyLoweringContext::new(db, &resolver).with_type_param_mode(ParamLoweringMode::Variable);
11281128
for (field_id, field_data) in var_data.fields().iter() {
1129-
res.insert(field_id, make_binders(db, &generics, ctx.lower_ty(&field_data.type_ref)))
1129+
res.insert(field_id, make_binders(db, &generics, ctx.lower_ty(&field_data.type_ref)));
11301130
}
11311131
Arc::new(res)
11321132
}

lib/la-arena/src/map.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ impl<T, V> ArenaMap<Idx<T>, V> {
4949
}
5050

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

5558
self.v.resize_with((idx + 1).max(self.v.len()), || None);
56-
self.v[idx] = Some(t);
59+
self.v[idx].replace(t)
5760
}
5861

5962
/// Returns a reference to the value associated with the provided index

0 commit comments

Comments
 (0)