mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Returns the old value for la_arena::ArenaMap::insert
This commit is contained in:
parent
1a94193602
commit
326ffee5b7
4 changed files with 8 additions and 5 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue