clippy
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 10 Apr 2025 20:10:17 +0000 (13:10 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 10 Apr 2025 20:10:17 +0000 (13:10 -0700)
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/output/render.rs
rust/pspp/src/output/text.rs
rust/pspp/src/output/text_line.rs
rust/pspp/src/sack.rs
rust/pspp/src/settings.rs

index 1fe7e56eaabde5515674b539a5f42abd3c9c8240..5cbc71912610bf8e24e81d73dba76e2438cccb92 100644 (file)
@@ -1923,7 +1923,7 @@ impl Display for DisplayValue<'_> {
                 f.write_str(local)
             }
 
-            ValueInner::Template { args, local, .. } => self.template(f, &local, args),
+            ValueInner::Template { args, local, .. } => self.template(f, local, args),
 
             ValueInner::Empty => Ok(()),
         }?;
index e4cd3ec3d6d979c5250fd29d56fc2cbd784c47aa..8d2e518c7e441a02d0b96442bd79d5c1d3363834 100644 (file)
@@ -373,7 +373,7 @@ impl Page {
     fn new(table: Arc<Table>, device: &dyn Device, min_width: usize, look: &Look) -> Self {
         use Axis2::*;
 
-        let n = table.n.clone();
+        let n = table.n;
 
         // Figure out rule widths.
         //
@@ -381,7 +381,7 @@ impl Page {
         // `rules[Y]` is horizontal rules.
         let rules = EnumMap::from_fn(|axis| {
             (0..=n[axis])
-                .map(|z| measure_rule(device, &*table, axis, z))
+                .map(|z| measure_rule(device, &table, axis, z))
                 .collect::<Vec<_>>()
         });
 
@@ -395,7 +395,7 @@ impl Page {
         // multiple columns.
         let mut unspanned_columns = [vec![0; n.x()], vec![0; n.x()]];
         for cell in table.cells().filter(|cell| cell.col_span() == 1) {
-            let mut w = device.measure_cell_width(&DrawCell::new(cell.inner(), &*table));
+            let mut w = device.measure_cell_width(&DrawCell::new(cell.inner(), &table));
             if device.params().px_size.is_some() {
                 if let Some(region) = table.heading_region(cell.coord) {
                     let wr = &heading_widths[region];
@@ -1441,7 +1441,7 @@ impl Pager {
                 .and_then(|x_break| {
                     x_break.next(
                         device,
-                        (device.params().size[Axis2::X] as f64 / self.scale as f64) as usize,
+                        (device.params().size[Axis2::X] as f64 / self.scale) as usize,
                     )
                 })
                 .map(|page| Break::new(page, Axis2::Y));
index 6489fd2a60186f2c66e891635aa3d218c8955713..31118aad69103ac3c4d77d64486b9b52ae9247e4 100644 (file)
@@ -433,53 +433,6 @@ fn new_line_breaks(
     }
 }
 
-#[cfg(test)]
-mod test {
-    use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
-
-    use crate::output::text::new_line_breaks;
-
-    #[test]
-    fn unicode_width() {
-        // `\n` is a control character, so [UnicodeWidthChar] considers it to
-        // have no width.
-        assert_eq!('\n'.width(), None);
-
-        // But [UnicodeWidthStr] has a different idea.
-        assert_eq!("\n".width(), 1);
-        assert_eq!("\r\n".width(), 1);
-    }
-
-    #[track_caller]
-    fn test_line_breaks(input: &str, width: usize, expected: Vec<&str>) {
-        let actual = new_line_breaks(input, width).collect::<Vec<_>>();
-        if expected != actual {
-            panic!("filling {input:?} to {width} columns:\nexpected: {expected:?}\nactual:   {actual:?}");
-        }
-    }
-    #[test]
-    fn line_breaks() {
-        for width in 0..=6 {
-            test_line_breaks("abc def ghi", width, vec!["abc", "def", "ghi"]);
-        }
-        for width in 7..=10 {
-            test_line_breaks("abc def ghi", width, vec!["abc def", "ghi"]);
-        }
-        test_line_breaks("abc def ghi", 11, vec!["abc def ghi"]);
-
-        for width in 0..=6 {
-            test_line_breaks("abc  def ghi", width, vec!["abc", "def", "ghi"]);
-        }
-        test_line_breaks("abc  def ghi", 7, vec!["abc", "def ghi"]);
-        for width in 8..=11 {
-            test_line_breaks("abc  def ghi", width, vec!["abc  def", "ghi"]);
-        }
-        test_line_breaks("abc  def ghi", 12, vec!["abc  def ghi"]);
-
-        test_line_breaks("abc\ndef\nghi", 2, vec!["abc", "def", "ghi"]);
-    }
-}
-
 impl Driver for TextDriver {
     fn name(&self) -> Cow<'static, str> {
         Cow::from("text")
@@ -574,7 +527,7 @@ impl Device for TextRenderer {
                 HorzAlign::Left => bb[X].start,
                 HorzAlign::Center => (bb[X].start + bb[X].end - width + 1) / 2,
             };
-            let Some((x, text)) = clip_text(&text, &(x..x + width), &clip[X]) else {
+            let Some((x, text)) = clip_text(text, &(x..x + width), &clip[X]) else {
                 continue;
             };
 
@@ -591,3 +544,50 @@ impl Device for TextRenderer {
         unimplemented!()
     }
 }
+
+#[cfg(test)]
+mod test {
+    use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
+
+    use crate::output::text::new_line_breaks;
+
+    #[test]
+    fn unicode_width() {
+        // `\n` is a control character, so [UnicodeWidthChar] considers it to
+        // have no width.
+        assert_eq!('\n'.width(), None);
+
+        // But [UnicodeWidthStr] has a different idea.
+        assert_eq!("\n".width(), 1);
+        assert_eq!("\r\n".width(), 1);
+    }
+
+    #[track_caller]
+    fn test_line_breaks(input: &str, width: usize, expected: Vec<&str>) {
+        let actual = new_line_breaks(input, width).collect::<Vec<_>>();
+        if expected != actual {
+            panic!("filling {input:?} to {width} columns:\nexpected: {expected:?}\nactual:   {actual:?}");
+        }
+    }
+    #[test]
+    fn line_breaks() {
+        for width in 0..=6 {
+            test_line_breaks("abc def ghi", width, vec!["abc", "def", "ghi"]);
+        }
+        for width in 7..=10 {
+            test_line_breaks("abc def ghi", width, vec!["abc def", "ghi"]);
+        }
+        test_line_breaks("abc def ghi", 11, vec!["abc def ghi"]);
+
+        for width in 0..=6 {
+            test_line_breaks("abc  def ghi", width, vec!["abc", "def", "ghi"]);
+        }
+        test_line_breaks("abc  def ghi", 7, vec!["abc", "def ghi"]);
+        for width in 8..=11 {
+            test_line_breaks("abc  def ghi", width, vec!["abc  def", "ghi"]);
+        }
+        test_line_breaks("abc  def ghi", 12, vec!["abc  def ghi"]);
+
+        test_line_breaks("abc\ndef\nghi", 2, vec!["abc", "def", "ghi"]);
+    }
+}
index 00cd44c7d76e1304141183d6a1796ab7da86e42c..d28dcc3417a2db25a8c354e5c4a35db38e5beecd 100644 (file)
@@ -282,6 +282,37 @@ impl Debug for Emphasis {
     }
 }
 
+pub fn clip_text<'a>(
+    text: &'a str,
+    bb: &Range<usize>,
+    clip: &Range<usize>,
+) -> Option<(usize, &'a str)> {
+    let mut x = bb.start;
+    let mut width = bb.len();
+
+    let mut iter = text.chars();
+    while x < clip.start {
+        let c = iter.next()?;
+        if let Some(w) = c.width() {
+            x += w;
+            width = width.checked_sub(w)?;
+        }
+    }
+    if x + width > clip.end {
+        if x >= clip.end {
+            return None;
+        }
+
+        while x + width > clip.end {
+            let c = iter.next_back()?;
+            if let Some(w) = c.width() {
+                width = width.checked_sub(w)?;
+            }
+        }
+    }
+    Some((x, iter.as_str()))
+}
+
 #[cfg(test)]
 mod test {
     use super::{Emphasis, TextLine};
@@ -561,34 +592,3 @@ mod test {
         }
     }
 }
-
-pub fn clip_text<'a>(
-    text: &'a str,
-    bb: &Range<usize>,
-    clip: &Range<usize>,
-) -> Option<(usize, &'a str)> {
-    let mut x = bb.start;
-    let mut width = bb.len();
-
-    let mut iter = text.chars();
-    while x < clip.start {
-        let c = iter.next()?;
-        if let Some(w) = c.width() {
-            x += w;
-            width = width.checked_sub(w)?;
-        }
-    }
-    if x + width > clip.end {
-        if x >= clip.end {
-            return None;
-        }
-
-        while x + width > clip.end {
-            let c = iter.next_back()?;
-            if let Some(w) = c.width() {
-                width = width.checked_sub(w)?;
-            }
-        }
-    }
-    Some((x, iter.as_str()))
-}
index c6be5d1eeff8ff8c78f0c6034c9c82604fe9c839..5a596e6263328ce34b829ca0c56230ca8004af0c 100644 (file)
@@ -108,8 +108,8 @@ fn parse_data_item(
             } else {
                 Err(lexer.error(format!(
                     "{integer} is not in the valid range [{},{}]",
-                    i32::min_value(),
-                    u32::max_value()
+                    i32::MIN,
+                    u32::MAX
                 )))?;
             };
         }
index 6bb33d7d138692a13ebbe55dccc0a83b585e4382..6aad3406058f20011b4f1077b3ab7767f69092ef 100644 (file)
@@ -128,7 +128,7 @@ impl Default for Settings {
 impl Settings {
     pub fn global() -> &'static Settings {
         static GLOBAL: OnceLock<Settings> = OnceLock::new();
-        &GLOBAL.get_or_init(|| Settings::default())
+        GLOBAL.get_or_init( Settings::default)
     }
 }