clippy
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 10 Apr 2025 18:07:12 +0000 (11:07 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 10 Apr 2025 18:07:12 +0000 (11:07 -0700)
rust/pspp/src/command/mod.rs
rust/pspp/src/dictionary.rs
rust/pspp/src/engine.rs
rust/pspp/src/format/display.rs
rust/pspp/src/format/parse.rs
rust/pspp/src/lex/command_name.rs
rust/pspp/src/macros.rs
rust/pspp/src/message.rs
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/output/text.rs

index b0480be4cb84ad950702509757df801b7f2756bc..f7caf2834bd3d731a4b388e7fe94a610eb2f043f 100644 (file)
@@ -78,14 +78,14 @@ impl<T> Parsed<T> {
     pub fn new(value: T, rest: TokenSlice, warnings: Diagnostics) -> Self {
         Self {
             value,
-            rest: rest,
+            rest,
             diagnostics: warnings,
         }
     }
     pub fn ok(value: T, rest: TokenSlice) -> Self {
         Self {
             value,
-            rest: rest,
+            rest,
             diagnostics: Diagnostics::default(),
         }
     }
@@ -354,7 +354,7 @@ where
         write!(f, "Subcommands[")?;
         for (index, item) in self.0.iter().enumerate() {
             if index > 0 {
-                write!(f, ",\n")?;
+                writeln!(f, ",")?;
             }
             write!(f, "{item:?}")?;
         }
@@ -760,7 +760,7 @@ fn parse_string(input: &TokenSlice) -> ParseResult<String> {
     }
 }
 
-impl<'a> FromTokens for Identifier {
+impl FromTokens for Identifier {
     fn from_tokens(input: &TokenSlice) -> ParseResult<Self>
     where
         Self: Sized,
@@ -769,7 +769,7 @@ impl<'a> FromTokens for Identifier {
     }
 }
 
-impl<'a> FromTokens for String {
+impl FromTokens for String {
     fn from_tokens(input: &TokenSlice) -> ParseResult<Self>
     where
         Self: Sized,
@@ -812,7 +812,7 @@ fn commands() -> &'static [Command] {
     }
 
     static COMMANDS: OnceLock<Vec<Command>> = OnceLock::new();
-    COMMANDS.get_or_init(|| new_commands()).as_slice()
+    COMMANDS.get_or_init(new_commands).as_slice()
 }
 
 fn parse_command_word(lexer: &mut TokenSlice, s: &mut String, n: usize) -> bool {
@@ -852,7 +852,7 @@ fn find_best_match(s: &str) -> (Option<&'static Command>, isize) {
 
 fn parse_command_name(
     lexer: &mut TokenSlice,
-    error: &Box<dyn Fn(Diagnostic)>,
+    error: &dyn Fn(Diagnostic),
 ) -> Result<(&'static Command, usize), ()> {
     let mut s = String::new();
     let mut word = 0;
@@ -909,7 +909,7 @@ pub fn end_of_command(context: &Context, range: RangeFrom<usize>) -> Result<Succ
     }
 }
 
-fn parse_in_state(mut lexer: TokenSlice, error: &Box<dyn Fn(Diagnostic)>, _state: State) {
+fn parse_in_state(mut lexer: TokenSlice, error: &dyn Fn(Diagnostic), _state: State) {
     match lexer.get_token(0) {
         None | Some(Token::End) => (),
         _ => match parse_command_name(&mut lexer, error) {
@@ -926,12 +926,12 @@ fn parse_in_state(mut lexer: TokenSlice, error: &Box<dyn Fn(Diagnostic)>, _state
     }
 }
 
-pub fn parse_command(lexer: TokenSlice, error: &Box<dyn Fn(Diagnostic)>) {
+pub fn parse_command(lexer: TokenSlice, error: &dyn Fn(Diagnostic)) {
     parse_in_state(lexer, error, State::Initial)
 }
 
 pub struct Context<'a> {
-    error: &'a Box<dyn Fn(Diagnostic)>,
+    error: &'a dyn Fn(Diagnostic),
     lexer: TokenSlice,
     command_name: Option<&'static str>,
 }
index 139180827e681f85c754758c60616ba882fcb1ee..67d5539ba72d3099c4597c7e745d4e16ed53b042 100644 (file)
@@ -215,7 +215,7 @@ impl Ord for Value {
 impl Hash for Value {
     fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
         match self {
-            Value::Number(number) => number.map(|x| OrderedFloat(x)).hash(state),
+            Value::Number(number) => number.map(OrderedFloat).hash(state),
             Value::String(string) => string.hash(state),
         }
     }
@@ -236,7 +236,7 @@ impl Value {
     pub fn as_string(&self) -> Option<&[u8]> {
         match self {
             Value::Number(_) => None,
-            Value::String(s) => Some(&*s),
+            Value::String(s) => Some(s),
         }
     }
 }
index 7e8c2fcaa528df47e157db3dd70935855717ab90..aeac1fcc37eb579acb473f7865b9d4155a95bda3 100644 (file)
@@ -6,6 +6,7 @@ use crate::{
 };
 use std::rc::Rc;
 
+#[derive(Default)]
 pub struct Engine;
 
 impl Engine {
index b7975c62a9d7feca421b254c253090a42e841343..b490e5fe39a42a722a32bee4e048d9976cf08245 100644 (file)
@@ -38,7 +38,7 @@ impl Value {
     }
 }
 
-impl<'a, 'b> Display for DisplayValue<'a, 'b> {
+impl Display for DisplayValue<'_, '_> {
     fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
         let number = match self.value {
             Value::Number(number) => *number,
@@ -464,7 +464,7 @@ impl<'a, 'b> DisplayValue<'a, 'b> {
                 'y' => {
                     let epoch = self.settings.epoch.0;
                     let offset = date.year() - epoch;
-                    if offset < 0 || offset > 99 {
+                    if !(0..=99).contains(&offset) {
                         return self.overflow(f);
                     }
                     write!(&mut output, "{:02}", date.year().abs() % 100).unwrap();
@@ -519,7 +519,7 @@ impl<'a, 'b> DisplayValue<'a, 'b> {
                     }
                     break;
                 }
-                c if n == 1 => output.push(c as char),
+                c if n == 1 => output.push(c),
                 _ => unreachable!(),
             }
         }
@@ -751,7 +751,7 @@ impl Display for Zeros {
     fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
         let mut n = self.0;
         while n > 0 {
-            static ZEROS: &'static str = "0000000000000000000000000000000000000000";
+            static ZEROS: &str = "0000000000000000000000000000000000000000";
             let chunk = n.min(ZEROS.len());
             f.write_str(&ZEROS[..chunk])?;
             n -= chunk;
@@ -773,7 +773,7 @@ fn output_hex(f: &mut Formatter<'_>, bytes: &[u8]) -> FmtResult {
 }
 
 fn allocate_space(want: usize, capacity: usize, used: &mut usize) -> bool {
-    if *used + want <= capacity as usize {
+    if *used + want <= capacity {
         *used += want;
         true
     } else {
index 040951d46470e89b4a217ec738291ba93f9b725b..6aa4463c57b08799771dee6c5804062d85f68c4c 100644 (file)
@@ -277,11 +277,11 @@ impl<'a> ParseValue<'a> {
             input
         }
 
-        if p.strip_prefix(&*style.prefix.s) {
+        if p.strip_prefix(&style.prefix.s) {
             p.strip_ws();
         }
         let sign = p.strip_one_of(&['-', '+']).inspect(|_| p.strip_ws());
-        if sign.is_some() && p.strip_prefix(&*style.prefix.s) {
+        if sign.is_some() && p.strip_prefix(&style.prefix.s) {
             p.strip_ws();
         }
         let integer = p.advance(strip_integer(p.0, style.grouping.map(char::from)));
@@ -300,7 +300,7 @@ impl<'a> ParseValue<'a> {
         } else {
             (None, "")
         };
-        if p.strip_prefix(&*style.suffix.s) {
+        if p.strip_prefix(&style.suffix.s) {
             p.strip_ws();
         }
 
@@ -398,7 +398,7 @@ impl<'a> ParseValue<'a> {
 
     fn parse_bcd(input: &[u8]) -> Result<u128, ParseErrorKind> {
         let mut value = 0;
-        for byte in input.into_iter().copied() {
+        for byte in input.iter().copied() {
             let hi = nibble(byte >> 4)?;
             let lo = nibble(byte & 0x0f)?;
             value = value * 100 + hi * 10 + lo;
@@ -492,7 +492,7 @@ impl<'a> ParseValue<'a> {
 
     fn parse_rbhex(&self, input: &str) -> Result<Value, ParseErrorKind> {
         self.parse_hex(input)
-            .map(|value| Value::Number(value.map(|number| f64::from_bits(number))))
+            .map(|value| Value::Number(value.map(f64::from_bits)))
     }
 
     fn parse_date(&self, input: &str) -> Result<Value, ParseErrorKind> {
@@ -586,7 +586,7 @@ impl<'a> ParseValue<'a> {
         Ok(Value::Number(Some(time_date)))
     }
 
-    fn parse_minute_second<'b>(&self, p: &mut StrParser<'b>) -> Result<f64, ParseErrorKind> {
+    fn parse_minute_second(&self, p: &mut StrParser<'_>) -> Result<f64, ParseErrorKind> {
         let minute = parse_int::<i32>(p)?;
         if self.format.type_ != Type::MTime && !(0..=59).contains(&minute) {
             return Err(ParseErrorKind::InvalidMinute(minute));
@@ -641,7 +641,7 @@ enum Sign {
     Negative,
 }
 
-fn parse_trailer<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
+fn parse_trailer(p: &mut StrParser<'_>) -> Result<(), ParseErrorKind> {
     p.strip_ws();
     if p.0.is_empty() {
         Ok(())
@@ -650,7 +650,7 @@ fn parse_trailer<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
     }
 }
 
-fn parse_sign<'a>(p: &mut StrParser<'a>, sign: Option<Sign>) -> Sign {
+fn parse_sign(p: &mut StrParser<'_>, sign: Option<Sign>) -> Sign {
     if let Some(sign) = sign {
         sign
     } else if p.strip_one_of(&['-', '+']) == Some('-') {
@@ -660,7 +660,7 @@ fn parse_sign<'a>(p: &mut StrParser<'a>, sign: Option<Sign>) -> Sign {
     }
 }
 
-fn parse_time<'a>(p: &mut StrParser<'a>) -> Result<f64, ParseErrorKind> {
+fn parse_time(p: &mut StrParser<'_>) -> Result<f64, ParseErrorKind> {
     let number = parse_int::<i32>(p)?;
     if number < 0 {
         return Err(ParseErrorKind::DateSyntax);
@@ -668,7 +668,7 @@ fn parse_time<'a>(p: &mut StrParser<'a>) -> Result<f64, ParseErrorKind> {
     Ok(number as f64)
 }
 
-fn parse_day<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_day(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
     let day = parse_int::<i32>(p)?;
     if (1..=31).contains(&day) {
         Ok(day)
@@ -677,7 +677,7 @@ fn parse_day<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
     }
 }
 
-fn parse_yday<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_yday(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
     let Some(s) = p.0.get(..3) else {
         return Err(ParseErrorKind::InvalidYDayLen);
     };
@@ -692,7 +692,7 @@ fn parse_yday<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
     Ok(yday)
 }
 
-fn parse_month<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_month(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
     if p.0.starts_with(|c: char| c.is_ascii_digit()) {
         let month = parse_int(p)?;
         if (1..=12).contains(&month) {
@@ -718,7 +718,7 @@ fn parse_month<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
     Err(ParseErrorKind::InvalidMonth)
 }
 
-fn parse_weekday<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_weekday(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
     static WEEKDAY_NAMES: [&str; 7] = ["su", "mo", "tu", "we", "th", "fr", "sa"];
     let name = p.strip_matches(|c| c.is_ascii_alphabetic());
     name.get(..2)
@@ -726,21 +726,21 @@ fn parse_weekday<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
         .ok_or(ParseErrorKind::InvalidWeekdayName)
 }
 
-fn parse_quarter<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_quarter(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
     match parse_int(p)? {
         quarter @ 1..=4 => Ok((quarter - 1) * 3 + 1),
         other => Err(ParseErrorKind::InvalidQuarter(other)),
     }
 }
 
-fn parse_week<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_week(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
     match parse_int(p)? {
         week @ 1..=53 => Ok((week - 1) * 7 + 1),
         other => Err(ParseErrorKind::InvalidWeek(other)),
     }
 }
 
-fn parse_time_delimiter<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
+fn parse_time_delimiter(p: &mut StrParser<'_>) -> Result<(), ParseErrorKind> {
     let delimiter = p.strip_matches(|c| c == ':' || c.is_ascii_whitespace());
     if !delimiter.is_empty() {
         Ok(())
@@ -749,7 +749,7 @@ fn parse_time_delimiter<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind>
     }
 }
 
-fn parse_date_delimiter<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
+fn parse_date_delimiter(p: &mut StrParser<'_>) -> Result<(), ParseErrorKind> {
     let delimiter = p
         .strip_matches(|c| c == '-' || c == '/' || c == '.' || c == ',' || c.is_ascii_whitespace());
     if !delimiter.is_empty() {
@@ -768,8 +768,8 @@ fn match_name(name: &str, candidates: &[&str]) -> Option<i32> {
     None
 }
 
-fn parse_year<'a>(
-    p: &mut StrParser<'a>,
+fn parse_year(
+    p: &mut StrParser<'_>,
     settings: &Settings,
     max_digits: usize,
 ) -> Result<i32, ParseErrorKind> {
@@ -787,7 +787,7 @@ fn parse_year<'a>(
     Ok(settings.epoch.apply(year))
 }
 
-fn parse_int<'a, T>(p: &mut StrParser<'a>) -> Result<T, ParseErrorKind>
+fn parse_int<'a, T>(p: &mut StrParser<'_>) -> Result<T, ParseErrorKind>
 where
     T: FromStr,
 {
@@ -1073,11 +1073,11 @@ mod test {
                     }
                     'm' => {
                         let m = self.date.month as usize - 1;
-                        static ROMAN: [&'static str; 12] = [
+                        static ROMAN: [&str; 12] = [
                             "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi",
                             "xii",
                         ];
-                        static ENGLISH: [&'static str; 12] = [
+                        static ENGLISH: [&str; 12] = [
                             "january",
                             "february",
                             "march",
index a954bee6a2b9d1afe89d603d33f4a778145fdb55..0e9957d4b309eac93abd0c19aab644c20777892b 100644 (file)
@@ -107,7 +107,7 @@ impl<'a, T> CommandMatcher<'a, T> {
     }
 }
 
-pub const COMMAND_NAMES: &'static [&'static str] = &[
+pub const COMMAND_NAMES: &[&str] = &[
     "2SLS",
     "ACF",
     "ADD DOCUMENT",
index bcd223c151f6cc66146ccd016a2e184af78ab0e4..57abc4ec36ad80098a13e509e3a6e1835a1fdb8d 100644 (file)
@@ -576,12 +576,10 @@ impl<'a> Parser<'a> {
                         ParserState::Arg
                     };
                 }
+            } else if self.args.iter().any(|arg| arg.is_none()) {
+                self.state = ParserState::Keyword;
             } else {
-                if self.args.iter().any(|arg| arg.is_none()) {
-                    self.state = ParserState::Keyword;
-                } else {
-                    self.finished();
-                }
+                self.finished();
             }
         }
     }
index 5b99802bf5ae1ea9530cf2f85dd8f98616a0a678..8942223a32acb0109756d5afd28d002cb9320b0d 100644 (file)
@@ -75,18 +75,11 @@ impl Display for Location {
             }
             let l1 = span.start.line;
             let l2 = span.end.line;
-            if let (Some(c1), Some(c2)) = (span.start.column, span.end.column) {
-                if l2 > l1 {
-                    write!(f, "{l1}.{c1}-{l2}.{}", c2 - 1)?;
-                } else {
-                    write!(f, "{l1}.{c1}-{}", c2 - 1)?;
-                }
-            } else {
-                if l2 > l1 {
-                    write!(f, "{l1}-{l2}")?;
-                } else {
-                    write!(f, "{l1}")?;
-                }
+            match (span.start.column.zip(span.end.column), l2 > l1) {
+                (Some((c1, c2)), true) => write!(f, "{l1}.{c1}-{l2}.{}", c2 - 1)?,
+                (Some((c1, c2)), false) => write!(f, "{l1}.{c1}-{}", c2 - 1)?,
+                (None, true) => write!(f, "{l1}-{l2}")?,
+                (None, false) => write!(f, "{l1}")?,
             }
         }
         Ok(())
index 8e315100b865ad9f4d86abf5cf44d91fb56384ea..7da87d5153e1ae6c769376227ff3ecd0b57d54b4 100644 (file)
@@ -403,7 +403,7 @@ impl DimensionBuilder {
         self.hide_all_labels = true;
         self
     }
-    fn build(mut self) -> Dimension {
+    fn build(self) -> Dimension {
         let mut leaves = Vec::with_capacity(self.len);
         let root = self.root.build(None, &mut leaves);
         Dimension {
@@ -443,10 +443,10 @@ impl GroupBuilder {
         self.push(value);
         self
     }
-    pub fn with_label_hidden(mut self) -> Self {
+    pub fn with_label_hidden(self) -> Self {
         self.with_show_label(false)
     }
-    pub fn with_label_shown(mut self) -> Self {
+    pub fn with_label_shown(self) -> Self {
         self.with_show_label(true)
     }
     pub fn with_show_label(mut self, show_label: bool) -> Self {
@@ -562,15 +562,8 @@ impl PivotTableBuilder {
             dimensions: Vec::with_capacity(self.dimensions.len()),
         });
         for d in self.dimensions {
-            let axis = d.axis;
-            let label_position = if axis == Axis3::Y && table.corner_text.is_none() {
-                self.look.row_label_position
-            } else {
-                LabelPosition::Nested
-            };
-            let d = d.build();
-            axes[axis].dimensions.push(dimensions.len());
-            dimensions.push(d);
+            axes[d.axis].dimensions.push(dimensions.len());
+            dimensions.push(d.build());
         }
         table.dimensions = dimensions;
         table.axes = axes;
index 6d6bbcbcc74a9fa0356fc609f5c75052bd01984c..226e92d036bfae04c781c6ef8e6a81f9029ef470 100644 (file)
@@ -46,7 +46,7 @@ impl TextRenderer {
             emphasis: true,
             width,
             min_hbreak: 20,
-            box_chars: &*&UNICODE_BOX,
+            box_chars: &*UNICODE_BOX,
             n_objects: 0,
             params: Params {
                 size: Coord2::new(width, usize::MAX),