mirror of
https://github.com/typst/typst
synced 2025-08-06 19:27:55 +08:00
refactor: avoid using transmute to work around the borrow checker
This commit is contained in:
parent
1b49034fb3
commit
b6048ccecd
@ -39,11 +39,12 @@ impl TableCtx {
|
|||||||
fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut TableCtxCell> {
|
fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut TableCtxCell> {
|
||||||
let cell = self.rows.get_mut(y)?.get_mut(x)?;
|
let cell = self.rows.get_mut(y)?.get_mut(x)?;
|
||||||
match cell {
|
match cell {
|
||||||
GridCell::Cell(cell) => {
|
// Reborrow here, so the borrow of `cell` doesn't get returned from
|
||||||
// HACK: Workaround for the second mutable borrow when resolving
|
// the function. Otherwise the borrow checker assumes `cell` borrows
|
||||||
// the spanned cell.
|
// `self.rows` for the entirety of the function, not just this match
|
||||||
Some(unsafe { std::mem::transmute(cell) })
|
// arm, and doesn't allow the second mutable borrow in the match arm
|
||||||
}
|
// below.
|
||||||
|
GridCell::Cell(_) => return self.rows[y][x].as_cell_mut(),
|
||||||
&mut GridCell::Spanned(x, y) => self.rows[y][x].as_cell_mut(),
|
&mut GridCell::Spanned(x, y) => self.rows[y][x].as_cell_mut(),
|
||||||
GridCell::Missing => None,
|
GridCell::Missing => None,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user