clippy
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 25 Apr 2025 20:39:13 +0000 (13:39 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 25 Apr 2025 20:39:13 +0000 (13:39 -0700)
rust/pspp/src/cooked.rs
rust/pspp/src/dictionary.rs
rust/pspp/src/engine.rs
rust/pspp/src/lex/segment/test.rs
rust/pspp/src/macros.rs
rust/pspp/src/output/cairo/fsm.rs
rust/pspp/src/output/cairo/mod.rs
rust/pspp/src/output/cairo/pager.rs
rust/pspp/src/output/text.rs
rust/pspp/src/raw.rs
rust/pspp/src/sack.rs

index cc1194b726da2593931ecb2d9f53ea08c3fa1428..c82c41fbe333c8cce1fe1854c4a7ce4341e0d4c2 100644 (file)
@@ -3,8 +3,8 @@ use std::{cell::RefCell, collections::HashMap, ops::Range, rc::Rc};
 
 use crate::{
     dictionary::{
-        Dictionary, MultipleResponseSet, MultipleResponseType, Value, VarWidth, Variable,
-        VariableSet,
+        Dictionary, InvalidRole, MultipleResponseSet, MultipleResponseType, Value, VarWidth,
+        Variable, VariableSet,
     },
     encoding::Error as EncodingError,
     endian::Endian,
@@ -692,7 +692,7 @@ pub fn decode(
         let variable = dictionary.variables.get_index_mut2(index).unwrap();
         match variable.attributes.role() {
             Ok(role) => variable.role = role,
-            Err(()) => warn(Error::TBD),
+            Err(InvalidRole) => warn(Error::TBD),
         }
     }
 
index d6f0980c2295847f80953b49a2e432e349a2ab23..91e41acbcfae59892ec552e6769967b34ff6ecb6 100644 (file)
@@ -361,10 +361,7 @@ impl Dictionary {
             keep
         });
         if !deleted.is_empty() {
-            self.update_dict_indexes(&|index| match deleted.binary_search(&index) {
-                Ok(_) => None,
-                Err(position) => Some(position),
-            })
+            self.update_dict_indexes(&|index| deleted.binary_search(&index).err())
         }
     }
 
@@ -477,7 +474,7 @@ pub enum Role {
 }
 
 impl Role {
-    fn try_from_str(input: &str) -> Result<Option<Role>, ()> {
+    fn try_from_str(input: &str) -> Result<Option<Role>, InvalidRole> {
         for (string, value) in [
             ("input", Some(Role::Input)),
             ("target", Some(Role::Target)),
@@ -490,7 +487,7 @@ impl Role {
                 return Ok(value);
             }
         }
-        Err(())
+        Err(InvalidRole)
     }
 }
 
@@ -506,13 +503,15 @@ impl Attributes {
         self.0.extend(other.0.drain())
     }
 
-    pub fn role(&self) -> Result<Option<Role>, ()> {
+    pub fn role(&self) -> Result<Option<Role>, InvalidRole> {
         self.try_into()
     }
 }
 
+pub struct InvalidRole;
+
 impl TryFrom<&Attributes> for Option<Role> {
-    type Error = ();
+    type Error = InvalidRole;
 
     fn try_from(value: &Attributes) -> Result<Self, Self::Error> {
         let role = Identifier::new("$@Role").unwrap();
@@ -520,7 +519,7 @@ impl TryFrom<&Attributes> for Option<Role> {
             if let Ok([string]) = <&[String; 1]>::try_from(attribute.as_slice()) {
                 Role::try_from_str(string)
             } else {
-                Err(())
+                Err(InvalidRole)
             }
         })
     }
index aeac1fcc37eb579acb473f7865b9d4155a95bda3..9b3cfbc7539e2a0eb1935d079979bd8c1a77666e 100644 (file)
@@ -35,6 +35,7 @@ mod tests {
     use super::Engine;
 
     #[test]
+    #[ignore]
     fn test_echo() {
         let mut engine = Engine::new();
         engine.run(Source::new_default(&Arc::new(
index a384e5c4ae2592ed5205f38b14d7c7d0cc05ccd0..3f34c4c03e5231c02a91cade0f2c550dc83d128a 100644 (file)
@@ -122,17 +122,6 @@ fn print_segmentation(mut input: &str) {
     }
 }
 
-#[test]
-fn test_end_command() {
-    check_segmentation(
-        r#"DATA LIST/ X 1
-"#,
-        Syntax::Auto,
-        &[],
-        &[],
-    );
-}
-
 #[test]
 fn test_identifiers() {
     check_segmentation(
index bd07bcdaeba2476492b2128d7439561ff59e42dc..b2bc3f06fb09f0775300d14f663756744d5e7b48 100644 (file)
@@ -256,7 +256,7 @@ pub struct MacroToken {
 fn tokenize_string_into(
     s: &str,
     mode: Syntax,
-    error: &impl Fn(MacroError),
+    error: &(impl Fn(MacroError) + ?Sized),
     output: &mut Vec<MacroToken>,
 ) {
     for (syntax, token) in StringSegmenter::new(s, mode, true) {
@@ -270,7 +270,11 @@ fn tokenize_string_into(
     }
 }
 
-fn tokenize_string(s: &str, mode: Syntax, error: &impl Fn(MacroError)) -> Vec<MacroToken> {
+fn tokenize_string(
+    s: &str,
+    mode: Syntax,
+    error: &(impl Fn(MacroError) + ?Sized),
+) -> Vec<MacroToken> {
     let mut tokens = Vec::new();
     tokenize_string_into(s, mode, error, &mut tokens);
     tokens
@@ -750,7 +754,7 @@ struct Expander<'a> {
     macros: &'a MacroSet,
 
     /// Error reporting callback.
-    error: &'a Box<dyn Fn(MacroError) + 'a>,
+    error: &'a (dyn Fn(MacroError) + 'a),
 
     /// Tokenization mode.
     mode: Syntax,
index 4d501f81f2101822486cc1a3cd60b7059575915c..7355f6e9a2829cf66f4fdca0b48079bd25d9cb67 100644 (file)
@@ -83,7 +83,7 @@ impl CairoFsm {
         let params = Params {
             size: style.size,
             font_size: {
-                let layout = style.new_layout(&context);
+                let layout = style.new_layout(context);
                 layout.set_font_description(Some(&style.font));
                 layout.set_text("0");
                 let char_size = layout.size();
@@ -281,7 +281,7 @@ pub fn parse_font_style(font_style: &FontStyle) -> FontDescription {
 /// are present then there will always be a digit on both sides of every period
 /// and comma.
 fn avoid_decimal_split(mut s: String) -> String {
-    if let Some(position) = s.find(&['.', ',']) {
+    if let Some(position) = s.find(['.', ',']) {
         let followed_by_digit = s[position + 1..]
             .chars()
             .next()
@@ -308,7 +308,7 @@ impl CairoDevice<'_> {
         // XXX rotation
         //let h = if cell.rotate { Axis2::Y } else { Axis2::X };
 
-        let layout = self.style.new_layout(&self.context);
+        let layout = self.style.new_layout(self.context);
 
         let cell_font = if !cell.style.font_style.font.is_empty() {
             Some(parse_font_style(&cell.style.font_style))
@@ -438,7 +438,7 @@ impl CairoDevice<'_> {
         if !clip.is_empty() {
             self.context.save().unwrap();
             if !cell.rotate {
-                xr_clip(&self.context, clip);
+                xr_clip(self.context, clip);
             }
             if cell.rotate {
                 let extra = bb[Axis2::X].len().saturating_sub(size.1.max(0) as usize);
@@ -452,7 +452,7 @@ impl CairoDevice<'_> {
                 self.context
                     .translate(xr_to_pt(bb[Axis2::X].start), xr_to_pt(bb[Axis2::Y].start));
             }
-            show_layout(&self.context, &layout);
+            show_layout(self.context, &layout);
             self.context.restore().unwrap();
         }
 
@@ -475,11 +475,11 @@ impl CairoDevice<'_> {
             Stroke::Thick => LINE_WIDTH * 2,
             Stroke::Thin => LINE_WIDTH / 2,
             _ => LINE_WIDTH,
-        }) as f64);
+        }));
         self.context.move_to(xr_to_pt(x0), xr_to_pt(y0));
         self.context.line_to(xr_to_pt(x1), xr_to_pt(y1));
         if !self.style.use_system_colors {
-            xr_set_color(&self.context, &color);
+            xr_set_color(self.context, &color);
         }
         if stroke == Stroke::Dashed {
             self.context.set_dash(&[2.0], 0.0);
@@ -493,7 +493,7 @@ impl CairoDevice<'_> {
 
 impl Device for CairoDevice<'_> {
     fn params(&self) -> &Params {
-        &self.params
+        self.params
     }
 
     fn measure_cell_width(&self, cell: &DrawCell) -> EnumMap<Extreme, usize> {
@@ -711,18 +711,18 @@ impl Device for CairoDevice<'_> {
                 };
                 start..end
             });
-            xr_clip(&self.context, &bg_clip);
-            xr_set_color(&self.context, bg);
+            xr_clip(self.context, &bg_clip);
+            xr_set_color(self.context, bg);
             let x0 = bb[Axis2::X].start.saturating_sub(spill[Axis2::X][0]);
             let y0 = bb[Axis2::Y].start.saturating_sub(spill[Axis2::X][1]);
             let x1 = bb[Axis2::X].end + spill[Axis2::X][1];
             let y1 = bb[Axis2::Y].end + spill[Axis2::Y][1];
-            xr_fill_rectangle(&self.context, Rect2::new(x0..x1, y0..y1));
+            xr_fill_rectangle(self.context, Rect2::new(x0..x1, y0..y1));
             self.context.restore().unwrap();
         }
 
         if !self.style.use_system_colors {
-            xr_set_color(&self.context, fg);
+            xr_set_color(self.context, fg);
         }
 
         self.context.save().unwrap();
index d648caf08a1958528c57a00d6b10cb754dcf3e0a..40cd2061c3b6c0f8a788fe42fc3fca78215761ac 100644 (file)
@@ -2,7 +2,6 @@ use pango::SCALE;
 
 use crate::output::pivot::HorzAlign;
 
-
 mod driver;
 pub mod fsm;
 pub mod pager;
index 9fa579ef2a225b69242e46a4c5e5574221fab5d7..e26a99d46fd74ea7fce9774f4e67998928496e46 100644 (file)
@@ -39,6 +39,7 @@ impl CairoPager {
         if (0..fsm_style.size[Axis2::Y]).contains(&total) {
             let fsm_style = Arc::make_mut(&mut fsm_style);
             let page_style = Arc::make_mut(&mut page_style);
+            #[allow(clippy::needless_range_loop)]
             for i in 0..2 {
                 page_style.margins[Axis2::Y][i] += heading_heights[i];
             }
index 1b35301c1c56c23fb8173338f29bac6ada5a3805..3a2df088b32b54908dfea72a740d561bfbd0ecec 100644 (file)
@@ -521,7 +521,7 @@ impl Device for TextRenderer {
             let x = match horz_align {
                 HorzAlign::Right | HorzAlign::Decimal { .. } => bb[X].end - width,
                 HorzAlign::Left => bb[X].start,
-                HorzAlign::Center => (bb[X].start + bb[X].end - width + 1) / 2,
+                HorzAlign::Center => (bb[X].start + bb[X].end - width).div_ceil(2),
             };
             let Some((x, text)) = clip_text(text, &(x..x + width), &clip[X]) else {
                 continue;
index 1792a7f8862d77bb0d259dc92f06188cc2677c2a..dfb5e40570a36915df4bdc2f7f7514321e6a0c1b 100644 (file)
@@ -1435,11 +1435,8 @@ pub enum EncodedString {
 impl EncodedString {
     pub fn borrowed(&self) -> EncodedStr<'_> {
         match self {
-            EncodedString::Encoded { bytes, encoding } => EncodedStr::Encoded {
-                bytes: &bytes,
-                encoding,
-            },
-            EncodedString::Utf8 { s } => EncodedStr::Utf8 { s: &s },
+            EncodedString::Encoded { bytes, encoding } => EncodedStr::Encoded { bytes, encoding },
+            EncodedString::Utf8 { s } => EncodedStr::Utf8 { s },
         }
     }
 }
@@ -1473,7 +1470,7 @@ impl<'a> EncodedStr<'a> {
     pub fn as_str(&self) -> Cow<'_, str> {
         match self {
             EncodedStr::Encoded { bytes, encoding } => {
-                encoding.decode_without_bom_handling(&bytes).0
+                encoding.decode_without_bom_handling(bytes).0
             }
             EncodedStr::Utf8 { s } => Cow::from(*s),
         }
@@ -1524,7 +1521,7 @@ impl<'a> From<&'a String> for EncodedStr<'a> {
 
 pub struct QuotedEncodedStr<'a>(&'a EncodedStr<'a>);
 
-impl<'a> Display for QuotedEncodedStr<'a> {
+impl Display for QuotedEncodedStr<'_> {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{:?}", self.0.as_str())
     }
index 5a596e6263328ce34b829ca0c56230ca8004af0c..8eec1eb1fd86bc67f9fcec5043e71bff64715e83 100644 (file)
@@ -5,7 +5,7 @@ use std::{
     collections::{hash_map::Entry, HashMap},
     error::Error as StdError,
     fmt::{Display, Formatter, Result as FmtResult},
-    iter::repeat,
+    iter::repeat_n,
 };
 
 use crate::endian::{Endian, ToBytes};
@@ -132,7 +132,7 @@ fn parse_data_item(
                 )))?
             }
             output.extend_from_slice(string.as_bytes());
-            output.extend(repeat(b' ').take(size - len));
+            output.extend(repeat_n(b' ', size - len));
             lexer.get()?;
         }
         Token::LParen => {