1 // Regression test for #82612.
3 use std::marker::PhantomData;
5 pub trait SparseSetIndex {
6 fn sparse_set_index(&self) -> usize;
8 pub struct SparseArray<I, V = I> {
9 values: Vec<Option<V>>,
10 marker: PhantomData<I>,
13 impl<I: SparseSetIndex, V> SparseArray<I, V> {
14 pub fn get_or_insert_with(&mut self, index: I, func: impl FnOnce() -> V) -> &mut V {
15 let index = index.sparse_set_index();
16 if index < self.values.len() {
17 let value = unsafe { self.values.get_unchecked_mut(index) };
18 value.get_or_insert_with(func) //~ ERROR mismatched types
20 unsafe { self.values.get_unchecked_mut(index).as_mut().unwrap() }