clippy::wrong_self_convention (#857)

This commit is contained in:
Marek Barvíř 2023-04-18 11:19:16 +02:00 committed by GitHub
parent 56673bcdf5
commit dd5e9723e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 33 deletions

View File

@ -237,7 +237,7 @@ impl<'a> StackLayouter<'a> {
// the region expands. // the region expands.
let mut size = self let mut size = self
.expand .expand
.select(self.initial, self.used.to_axes(self.axis)) .select(self.initial, self.used.into_axes(self.axis))
.min(self.initial); .min(self.initial);
// Expand fully if there are fr spacings. // Expand fully if there are fr spacings.
@ -318,7 +318,7 @@ impl<T> Gen<T> {
} }
/// Convert to the specific representation, given the current main axis. /// Convert to the specific representation, given the current main axis.
fn to_axes(self, main: Axis) -> Axes<T> { fn into_axes(self, main: Axis) -> Axes<T> {
match main { match main {
Axis::X => Axes::new(self.main, self.cross), Axis::X => Axes::new(self.main, self.cross),
Axis::Y => Axes::new(self.cross, self.main), Axis::Y => Axes::new(self.cross, self.main),
@ -334,6 +334,6 @@ impl Gen<Abs> {
/// Convert to a point. /// Convert to a point.
fn to_point(self, main: Axis) -> Point { fn to_point(self, main: Axis) -> Point {
self.to_axes(main).to_point() self.into_axes(main).to_point()
} }
} }

View File

@ -91,7 +91,7 @@ impl LayoutMath for AccentElem {
let mut frame = Frame::new(size); let mut frame = Frame::new(size);
frame.set_baseline(baseline); frame.set_baseline(baseline);
frame.push_frame(accent_pos, accent); frame.push_frame(accent_pos, accent);
frame.push_frame(base_pos, base.to_frame()); frame.push_frame(base_pos, base.into_frame());
ctx.push(FrameFragment::new(ctx, frame).with_base_ascent(base_ascent)); ctx.push(FrameFragment::new(ctx, frame).with_base_ascent(base_ascent));
Ok(()) Ok(())

View File

@ -191,18 +191,18 @@ fn scripts(
let mut frame = Frame::new(Size::new(width, ascent + descent)); let mut frame = Frame::new(Size::new(width, ascent + descent));
frame.set_baseline(ascent); frame.set_baseline(ascent);
frame.push_frame(base_pos, base.to_frame()); frame.push_frame(base_pos, base.into_frame());
if let Some(sup) = sup { if let Some(sup) = sup {
let sup_pos = let sup_pos =
Point::new(sup_delta + base_width, ascent - shift_up - sup.ascent()); Point::new(sup_delta + base_width, ascent - shift_up - sup.ascent());
frame.push_frame(sup_pos, sup.to_frame()); frame.push_frame(sup_pos, sup.into_frame());
} }
if let Some(sub) = sub { if let Some(sub) = sub {
let sub_pos = let sub_pos =
Point::new(sub_delta + base_width, ascent + shift_down - sub.ascent()); Point::new(sub_delta + base_width, ascent + shift_down - sub.ascent());
frame.push_frame(sub_pos, sub.to_frame()); frame.push_frame(sub_pos, sub.into_frame());
} }
ctx.push(FrameFragment::new(ctx, frame).with_class(class)); ctx.push(FrameFragment::new(ctx, frame).with_class(class));
@ -245,17 +245,17 @@ fn limits(
let mut frame = Frame::new(Size::new(width, height)); let mut frame = Frame::new(Size::new(width, height));
frame.set_baseline(base_pos.y + base.ascent()); frame.set_baseline(base_pos.y + base.ascent());
frame.push_frame(base_pos, base.to_frame()); frame.push_frame(base_pos, base.into_frame());
if let Some(top) = top { if let Some(top) = top {
let top_pos = Point::with_x((width - top.width()) / 2.0 + delta); let top_pos = Point::with_x((width - top.width()) / 2.0 + delta);
frame.push_frame(top_pos, top.to_frame()); frame.push_frame(top_pos, top.into_frame());
} }
if let Some(bottom) = bottom { if let Some(bottom) = bottom {
let bottom_pos = let bottom_pos =
Point::new((width - bottom.width()) / 2.0 - delta, height - bottom.height()); Point::new((width - bottom.width()) / 2.0 - delta, height - bottom.height());
frame.push_frame(bottom_pos, bottom.to_frame()); frame.push_frame(bottom_pos, bottom.into_frame());
} }
ctx.push(FrameFragment::new(ctx, frame).with_class(class)); ctx.push(FrameFragment::new(ctx, frame).with_class(class));

View File

@ -98,7 +98,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
elem: &dyn LayoutMath, elem: &dyn LayoutMath,
) -> SourceResult<MathFragment> { ) -> SourceResult<MathFragment> {
let row = self.layout_fragments(elem)?; let row = self.layout_fragments(elem)?;
Ok(MathRow::new(row).to_fragment(self)) Ok(MathRow::new(row).into_fragment(self))
} }
pub fn layout_fragments( pub fn layout_fragments(
@ -116,7 +116,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
} }
pub fn layout_frame(&mut self, elem: &dyn LayoutMath) -> SourceResult<Frame> { pub fn layout_frame(&mut self, elem: &dyn LayoutMath) -> SourceResult<Frame> {
Ok(self.layout_fragment(elem)?.to_frame()) Ok(self.layout_fragment(elem)?.into_frame())
} }
pub fn layout_content(&mut self, content: &Content) -> SourceResult<Frame> { pub fn layout_content(&mut self, content: &Content) -> SourceResult<Frame> {
@ -151,7 +151,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
let c = self.style.styled_char(c); let c = self.style.styled_char(c);
fragments.push(GlyphFragment::new(self, c, span).into()); fragments.push(GlyphFragment::new(self, c, span).into());
} }
let frame = MathRow::new(fragments).to_frame(self); let frame = MathRow::new(fragments).into_frame(self);
FrameFragment::new(self, frame).into() FrameFragment::new(self, frame).into()
} else { } else {
// Anything else is handled by Typst's standard text layout. // Anything else is handled by Typst's standard text layout.

View File

@ -105,9 +105,9 @@ impl MathFragment {
} }
} }
pub fn to_frame(self) -> Frame { pub fn into_frame(self) -> Frame {
match self { match self {
Self::Glyph(glyph) => glyph.to_frame(), Self::Glyph(glyph) => glyph.into_frame(),
Self::Variant(variant) => variant.frame, Self::Variant(variant) => variant.frame,
Self::Frame(fragment) => fragment.frame, Self::Frame(fragment) => fragment.frame,
_ => Frame::new(self.size()), _ => Frame::new(self.size()),
@ -201,7 +201,7 @@ impl GlyphFragment {
self.ascent + self.descent self.ascent + self.descent
} }
pub fn to_variant(self) -> VariantFragment { pub fn into_variant(self) -> VariantFragment {
VariantFragment { VariantFragment {
c: self.c, c: self.c,
id: Some(self.id), id: Some(self.id),
@ -210,11 +210,11 @@ impl GlyphFragment {
italics_correction: self.italics_correction, italics_correction: self.italics_correction,
class: self.class, class: self.class,
span: self.span, span: self.span,
frame: self.to_frame(), frame: self.into_frame(),
} }
} }
pub fn to_frame(self) -> Frame { pub fn into_frame(self) -> Frame {
let item = TextItem { let item = TextItem {
font: self.font.clone(), font: self.font.clone(),
size: self.font_size, size: self.font_size,

View File

@ -268,7 +268,7 @@ fn layout_mat_body(ctx: &mut MathContext, rows: &[Vec<Content>]) -> SourceResult
let points = alignments(&col); let points = alignments(&col);
let mut y = Abs::zero(); let mut y = Abs::zero();
for ((cell, &ascent), &descent) in col.into_iter().zip(&ascents).zip(&descents) { for ((cell, &ascent), &descent) in col.into_iter().zip(&ascents).zip(&descents) {
let cell = cell.to_aligned_frame(ctx, &points, Align::Center); let cell = cell.into_aligned_frame(ctx, &points, Align::Center);
let pos = let pos =
Point::new(x + (rcol - cell.width()) / 2.0, y + ascent - cell.ascent()); Point::new(x + (rcol - cell.width()) / 2.0, y + ascent - cell.ascent());
frame.push_frame(pos, cell); frame.push_frame(pos, cell);

View File

@ -38,7 +38,7 @@ impl LayoutMath for OpElem {
let fragment = let fragment =
ctx.layout_text(&TextElem::new(self.text()).spanned(self.span()))?; ctx.layout_text(&TextElem::new(self.text()).spanned(self.span()))?;
ctx.push( ctx.push(
FrameFragment::new(ctx, fragment.to_frame()) FrameFragment::new(ctx, fragment.into_frame())
.with_class(MathClass::Large) .with_class(MathClass::Large)
.with_limits(self.limits(ctx.styles())), .with_limits(self.limits(ctx.styles())),
); );

View File

@ -99,21 +99,21 @@ impl MathRow {
self.iter().map(MathFragment::descent).max().unwrap_or_default() self.iter().map(MathFragment::descent).max().unwrap_or_default()
} }
pub fn to_frame(self, ctx: &MathContext) -> Frame { pub fn into_frame(self, ctx: &MathContext) -> Frame {
let styles = ctx.styles(); let styles = ctx.styles();
let align = AlignElem::alignment_in(styles).x.resolve(styles); let align = AlignElem::alignment_in(styles).x.resolve(styles);
self.to_aligned_frame(ctx, &[], align) self.into_aligned_frame(ctx, &[], align)
} }
pub fn to_fragment(self, ctx: &MathContext) -> MathFragment { pub fn into_fragment(self, ctx: &MathContext) -> MathFragment {
if self.0.len() == 1 { if self.0.len() == 1 {
self.0.into_iter().next().unwrap() self.0.into_iter().next().unwrap()
} else { } else {
FrameFragment::new(ctx, self.to_frame(ctx)).into() FrameFragment::new(ctx, self.into_frame(ctx)).into()
} }
} }
pub fn to_aligned_frame( pub fn into_aligned_frame(
mut self, mut self,
ctx: &MathContext, ctx: &MathContext,
points: &[Abs], points: &[Abs],
@ -141,7 +141,7 @@ impl MathRow {
let mut frame = Frame::new(Size::zero()); let mut frame = Frame::new(Size::zero());
for (i, row) in rows.into_iter().enumerate() { for (i, row) in rows.into_iter().enumerate() {
let sub = row.to_line_frame(&points, align); let sub = row.into_line_frame(&points, align);
let size = frame.size_mut(); let size = frame.size_mut();
if i > 0 { if i > 0 {
size.y += leading; size.y += leading;
@ -157,11 +157,11 @@ impl MathRow {
} }
frame frame
} else { } else {
self.to_line_frame(points, align) self.into_line_frame(points, align)
} }
} }
fn to_line_frame(self, points: &[Abs], align: Align) -> Frame { fn into_line_frame(self, points: &[Abs], align: Align) -> Frame {
let ascent = self.ascent(); let ascent = self.ascent();
let descent = self.descent(); let descent = self.descent();
let size = Size::new(Abs::zero(), ascent + descent); let size = Size::new(Abs::zero(), ascent + descent);
@ -194,7 +194,7 @@ impl MathRow {
let y = ascent - fragment.ascent(); let y = ascent - fragment.ascent();
let pos = Point::new(x, y); let pos = Point::new(x, y);
x += fragment.width(); x += fragment.width();
frame.push_frame(pos, fragment.to_frame()); frame.push_frame(pos, fragment.into_frame());
} }
frame.size_mut().x = x; frame.size_mut().x = x;

View File

@ -57,7 +57,7 @@ fn stretch_glyph(
// If the base glyph is good enough, use it. // If the base glyph is good enough, use it.
let advance = if horizontal { base.width } else { base.height() }; let advance = if horizontal { base.width } else { base.height() };
if short_target <= advance { if short_target <= advance {
return base.to_variant(); return base.into_variant();
} }
// Search for a pre-made variant with a good advance. // Search for a pre-made variant with a good advance.
@ -73,7 +73,7 @@ fn stretch_glyph(
// This is either good or the best we've got. // This is either good or the best we've got.
if short_target <= best_advance || construction.assembly.is_none() { if short_target <= best_advance || construction.assembly.is_none() {
return GlyphFragment::with_id(ctx, base.c, best_id, base.span).to_variant(); return GlyphFragment::with_id(ctx, base.c, best_id, base.span).into_variant();
} }
// Assemble from parts. // Assemble from parts.
@ -169,7 +169,7 @@ fn assemble(
} else { } else {
Point::with_y(full - offset - fragment.height()) Point::with_y(full - offset - fragment.height())
}; };
frame.push_frame(pos, fragment.to_frame()); frame.push_frame(pos, fragment.into_frame());
offset += advance; offset += advance;
} }

View File

@ -242,7 +242,7 @@ pub(super) fn stack(
let points = alignments(&rows); let points = alignments(&rows);
let rows: Vec<_> = rows let rows: Vec<_> = rows
.into_iter() .into_iter()
.map(|row| row.to_aligned_frame(ctx, &points, align)) .map(|row| row.into_aligned_frame(ctx, &points, align))
.collect(); .collect();
for row in &rows { for row in &rows {