Migrate to 2024 edition

This commit is contained in:
Laurenz 2025-07-21 14:19:24 +02:00
parent eed75ca4d6
commit 4bbd4e195b
9 changed files with 16 additions and 16 deletions

View File

@ -7,7 +7,7 @@ resolver = "2"
version = "0.13.1" version = "0.13.1"
rust-version = "1.88" # also change in ci.yml rust-version = "1.88" # also change in ci.yml
authors = ["The Typst Project Developers"] authors = ["The Typst Project Developers"]
edition = "2021" edition = "2024"
homepage = "https://typst.app" homepage = "https://typst.app"
repository = "https://github.com/typst/typst" repository = "https://github.com/typst/typst"
license = "Apache-2.0" license = "Apache-2.0"

View File

@ -50,7 +50,7 @@ pub fn jump_from_click(
} }
// If there's no link, search for a jump target. // If there's no link, search for a jump target.
for (mut pos, item) in frame.items().rev() { for &(mut pos, ref item) in frame.items().rev() {
match item { match item {
FrameItem::Group(group) => { FrameItem::Group(group) => {
let pos = click - pos; let pos = click - pos;
@ -177,7 +177,7 @@ pub fn jump_from_cursor(
/// Find the position of a span in a frame. /// Find the position of a span in a frame.
fn find_in_frame(frame: &Frame, span: Span) -> Option<Point> { fn find_in_frame(frame: &Frame, span: Span) -> Option<Point> {
for (mut pos, item) in frame.items() { for &(mut pos, ref item) in frame.items() {
if let FrameItem::Group(group) = item { if let FrameItem::Group(group) = item {
if let Some(point) = find_in_frame(&group.frame, span) { if let Some(point) = find_in_frame(&group.frame, span) {
return Some(pos + point.transform(group.transform)); return Some(pos + point.transform(group.transform));

View File

@ -1228,7 +1228,7 @@ impl<'a> GridLayouter<'a> {
.skip(parent.y) .skip(parent.y)
.take(rowspan) .take(rowspan)
.rev() .rev()
.find(|(_, &row)| row == Sizing::Auto) .find(|&(_, &row)| row == Sizing::Auto)
.map(|(y, _)| y); .map(|(y, _)| y);
if last_spanned_auto_row != Some(y) { if last_spanned_auto_row != Some(y) {

View File

@ -55,7 +55,7 @@ pub fn layout_lr(
// Handle MathFragment::Glyph fragments that should be scaled up. // Handle MathFragment::Glyph fragments that should be scaled up.
for fragment in inner_fragments.iter_mut() { for fragment in inner_fragments.iter_mut() {
if let MathFragment::Glyph(ref mut glyph) = fragment { if let MathFragment::Glyph(glyph) = fragment {
if glyph.mid_stretched == Some(false) { if glyph.mid_stretched == Some(false) {
glyph.mid_stretched = Some(true); glyph.mid_stretched = Some(true);
scale(ctx, fragment, relative_to, height); scale(ctx, fragment, relative_to, height);
@ -95,7 +95,7 @@ pub fn layout_mid(
let mut fragments = ctx.layout_into_fragments(&elem.body, styles)?; let mut fragments = ctx.layout_into_fragments(&elem.body, styles)?;
for fragment in &mut fragments { for fragment in &mut fragments {
if let MathFragment::Glyph(ref mut glyph) = fragment { if let MathFragment::Glyph(glyph) = fragment {
glyph.mid_stretched = Some(false); glyph.mid_stretched = Some(false);
glyph.class = MathClass::Relation; glyph.class = MathClass::Relation;
} }

View File

@ -37,7 +37,7 @@ pub fn stretch_fragment(
) { ) {
let size = fragment.size(); let size = fragment.size();
let MathFragment::Glyph(ref mut glyph) = fragment else { return }; let MathFragment::Glyph(glyph) = fragment else { return };
// Return if we attempt to stretch along an axis which isn't stretchable, // Return if we attempt to stretch along an axis which isn't stretchable,
// so that the original fragment isn't modified. // so that the original fragment isn't modified.

View File

@ -47,7 +47,7 @@ impl Engine<'_> {
} }
/// Runs tasks on the engine in parallel. /// Runs tasks on the engine in parallel.
pub fn parallelize<P, I, T, U, F>(&mut self, iter: P, f: F) -> impl Iterator<Item = U> pub fn parallelize<P, I, T, U, F>(&mut self, iter: P, f: F) -> impl Iterator<Item = U> + use<P, I, T, U, F>
where where
P: IntoIterator<IntoIter = I>, P: IntoIterator<IntoIter = I>,
I: Iterator<Item = T>, I: Iterator<Item = T>,

View File

@ -327,7 +327,7 @@ where
self.0.entry(key).or_default().push(value); self.0.entry(key).or_default().push(value);
} }
fn take(&mut self, key: &K) -> Option<impl Iterator<Item = V>> { fn take(&mut self, key: &K) -> Option<impl Iterator<Item = V> + use<K, V>> {
self.0.remove(key).map(|vec| vec.into_iter()) self.0.remove(key).map(|vec| vec.into_iter())
} }
} }

View File

@ -9,7 +9,7 @@ use crate::convert::GlobalContext;
pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata { pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
let creator = format!("Typst {}", env!("CARGO_PKG_VERSION")); let creator = format!("Typst {}", env!("CARGO_PKG_VERSION"));
let lang = gc.languages.iter().max_by_key(|(_, &count)| count).map(|(&l, _)| l); let lang = gc.languages.iter().max_by_key(|&(_, &count)| count).map(|(&l, _)| l);
let dir = if lang.map(Lang::dir) == Some(Dir::RTL) { let dir = if lang.map(Lang::dir) == Some(Dir::RTL) {
TextDirection::RightToLeft TextDirection::RightToLeft

View File

@ -16,11 +16,11 @@ use std::ptr::NonNull;
/// to a value whose type implements the trait of `T` and the `vtable` must have /// to a value whose type implements the trait of `T` and the `vtable` must have
/// been extracted with [`vtable`]. /// been extracted with [`vtable`].
#[track_caller] #[track_caller]
pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *const T { pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *const T { unsafe {
let fat = FatPointer { data, vtable }; let fat = FatPointer { data, vtable };
debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>()); debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
mem::transmute_copy::<FatPointer, *const T>(&fat) mem::transmute_copy::<FatPointer, *const T>(&fat)
} }}
/// Create a mutable fat pointer from a data address and a vtable address. /// Create a mutable fat pointer from a data address and a vtable address.
/// ///
@ -29,23 +29,23 @@ pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *
/// to a value whose type implements the trait of `T` and the `vtable` must have /// to a value whose type implements the trait of `T` and the `vtable` must have
/// been extracted with [`vtable`]. /// been extracted with [`vtable`].
#[track_caller] #[track_caller]
pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) -> *mut T { pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) -> *mut T { unsafe {
let fat = FatPointer { data, vtable }; let fat = FatPointer { data, vtable };
debug_assert_eq!(Layout::new::<*mut T>(), Layout::new::<FatPointer>()); debug_assert_eq!(Layout::new::<*mut T>(), Layout::new::<FatPointer>());
mem::transmute_copy::<FatPointer, *mut T>(&fat) mem::transmute_copy::<FatPointer, *mut T>(&fat)
} }}
/// Extract the address to a trait object's vtable. /// Extract the address to a trait object's vtable.
/// ///
/// # Safety /// # Safety
/// Must only be called when `T` is a `dyn Trait`. /// Must only be called when `T` is a `dyn Trait`.
#[track_caller] #[track_caller]
pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> NonNull<()> { pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> NonNull<()> { unsafe {
debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>()); debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
NonNull::new_unchecked( NonNull::new_unchecked(
mem::transmute_copy::<*const T, FatPointer>(&ptr).vtable as *mut (), mem::transmute_copy::<*const T, FatPointer>(&ptr).vtable as *mut (),
) )
} }}
/// The memory representation of a trait object pointer. /// The memory representation of a trait object pointer.
/// ///