Skip to content

Commit 5d57d46

Browse files
committed
Remove unused uninit/assume_init on Matrix
The `Vec<C>` and `Vec<MaybeUninit<C>>` don't have any long-term guarantee of having the same in-memory representation.
1 parent 0b44f86 commit 5d57d46

File tree

2 files changed

+0
-49
lines changed

2 files changed

+0
-49
lines changed

src/matrix.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use itertools::Itertools;
88
use num_traits::Signed;
99
use std::collections::BTreeSet;
1010
use std::iter::FusedIterator;
11-
use std::mem::MaybeUninit;
1211
use std::ops::{Deref, DerefMut, Index, IndexMut, Neg, Range};
1312
use std::slice::{Iter, IterMut};
1413
use thiserror::Error;
@@ -232,20 +231,6 @@ impl<C> Matrix<C> {
232231
})
233232
}
234233

235-
/// Construct a new Matrix with uninitialized content.
236-
pub fn new_uninit(rows: usize, columns: usize) -> Matrix<MaybeUninit<C>> {
237-
let data_len = rows * columns;
238-
let mut data = Vec::with_capacity(data_len);
239-
unsafe {
240-
data.set_len(data_len);
241-
}
242-
Matrix {
243-
rows,
244-
columns,
245-
data,
246-
}
247-
}
248-
249234
/// Create new square matrix from vector values. The first value
250235
/// will be assigned to index (0, 0), the second one to index (0, 1),
251236
/// and so on. An error is returned if the number of values is not a
@@ -636,23 +621,6 @@ impl<C> Matrix<C> {
636621
}
637622
}
638623

639-
impl<C> Matrix<MaybeUninit<C>> {
640-
/// Convert to `Matrix<C>`.
641-
///
642-
/// # Safety
643-
///
644-
/// As with [`MaybeUninit::assume_init()`], it is up to the caller to guarantee
645-
/// that the value really is in an initialized state. Calling this when the content
646-
/// is not yet fully initialized causes immediate undefined behavior.
647-
pub unsafe fn assume_init(self) -> Matrix<C> {
648-
Matrix {
649-
rows: self.rows,
650-
columns: self.columns,
651-
data: std::mem::transmute(self.data),
652-
}
653-
}
654-
}
655-
656624
impl<C> Index<(usize, usize)> for Matrix<C> {
657625
type Output = C;
658626

tests/matrix.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -574,23 +574,6 @@ fn in_direction() {
574574
);
575575
}
576576

577-
#[test]
578-
fn uninit() {
579-
struct NonClonable(usize);
580-
let mut mat = Matrix::<NonClonable>::new_uninit(3, 3);
581-
for row in 0..mat.rows {
582-
for column in 0..mat.columns {
583-
mat[(row, column)].write(NonClonable(3 * row + column));
584-
}
585-
}
586-
let mat = unsafe { mat.assume_init() };
587-
for row in 0..mat.rows {
588-
for column in 0..mat.columns {
589-
assert_eq!(mat[(row, column)].0, row * 3 + column);
590-
}
591-
}
592-
}
593-
594577
#[test]
595578
fn map() {
596579
let m = Matrix::new(3, 3, 10);

0 commit comments

Comments
 (0)