]> Repositorios git - scryer-prolog.git/commitdiff
fix some clippy lint warnings
authorSkgland <[email protected]>
Sat, 6 Feb 2021 18:45:21 +0000 (19:45 +0100)
committerSkgland <[email protected]>
Sat, 6 Feb 2021 21:13:05 +0000 (22:13 +0100)
crates/prolog_parser/src/ast.rs
crates/prolog_parser/src/lexer.rs
crates/prolog_parser/src/parser.rs
crates/prolog_parser/src/tabled_rc.rs

index 5810b94c109124705722b6e3a73888cee6b95bd4..6f05bcba6e561c6a0a820e8bef2b68ab0772b85b 100644 (file)
@@ -197,8 +197,8 @@ impl RegType {
 impl fmt::Display for RegType {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            &RegType::Perm(val) => write!(f, "Y{}", val),
-            &RegType::Temp(val) => write!(f, "X{}", val),
+            RegType::Perm(val) => write!(f, "Y{}", val),
+            RegType::Temp(val) => write!(f, "X{}", val),
         }
     }
 }
@@ -220,10 +220,10 @@ impl VarReg {
 impl fmt::Display for VarReg {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            &VarReg::Norm(RegType::Perm(reg)) => write!(f, "Y{}", reg),
-            &VarReg::Norm(RegType::Temp(reg)) => write!(f, "X{}", reg),
-            &VarReg::ArgAndNorm(RegType::Perm(reg), arg) => write!(f, "Y{} A{}", reg, arg),
-            &VarReg::ArgAndNorm(RegType::Temp(reg), arg) => write!(f, "X{} A{}", reg, arg),
+            VarReg::Norm(RegType::Perm(reg)) => write!(f, "Y{}", reg),
+            VarReg::Norm(RegType::Temp(reg)) => write!(f, "X{}", reg),
+            VarReg::ArgAndNorm(RegType::Perm(reg), arg) => write!(f, "Y{} A{}", reg, arg),
+            VarReg::ArgAndNorm(RegType::Temp(reg), arg) => write!(f, "X{} A{}", reg, arg),
         }
     }
 }
@@ -382,16 +382,16 @@ impl ParserError {
 
     pub fn as_str(&self) -> &'static str {
         match self {
-            &ParserError::BackQuotedString(..) => "back_quoted_string",
-            &ParserError::UnexpectedChar(..) => "unexpected_char",
-            &ParserError::UnexpectedEOF => "unexpected_end_of_file",
-            &ParserError::IncompleteReduction(..) => "incomplete_reduction",
-            &ParserError::InvalidSingleQuotedCharacter(..) => "invalid_single_quoted_character",
-            &ParserError::IO(_) => "input_output_error",
-            &ParserError::MissingQuote(..) => "missing_quote",
-            &ParserError::NonPrologChar(..) => "non_prolog_character",
-            &ParserError::ParseBigInt(..) => "cannot_parse_big_int",
-            &ParserError::Utf8Error(..) => "utf8_conversion_error",
+            ParserError::BackQuotedString(..) => "back_quoted_string",
+            ParserError::UnexpectedChar(..) => "unexpected_char",
+            ParserError::UnexpectedEOF => "unexpected_end_of_file",
+            ParserError::IncompleteReduction(..) => "incomplete_reduction",
+            ParserError::InvalidSingleQuotedCharacter(..) => "invalid_single_quoted_character",
+            ParserError::IO(_) => "input_output_error",
+            ParserError::MissingQuote(..) => "missing_quote",
+            ParserError::NonPrologChar(..) => "non_prolog_character",
+            ParserError::ParseBigInt(..) => "cannot_parse_big_int",
+            ParserError::Utf8Error(..) => "utf8_conversion_error",
         }
     }
 }
@@ -525,21 +525,21 @@ pub enum Constant {
 impl fmt::Display for Constant {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            &Constant::Atom(ref atom, _) => {
+            Constant::Atom(ref atom, _) => {
                 if atom.as_str().chars().any(|c| "`.$'\" ".contains(c)) {
                     write!(f, "'{}'", atom.as_str())
                 } else {
                     write!(f, "{}", atom.as_str())
                 }
             }
-            &Constant::Char(c) => write!(f, "'{}'", c as u32),
-            &Constant::EmptyList => write!(f, "[]"),
-            &Constant::Fixnum(n) => write!(f, "{}", n),
-            &Constant::Integer(ref n) => write!(f, "{}", n),
-            &Constant::Rational(ref n) => write!(f, "{}", n),
-            &Constant::Float(ref n) => write!(f, "{}", n),
-            &Constant::String(ref s) => write!(f, "\"{}\"", &s),
-            &Constant::Usize(integer) => write!(f, "u{}", integer),
+            Constant::Char(c) => write!(f, "'{}'", *c as u32),
+            Constant::EmptyList => write!(f, "[]"),
+            Constant::Fixnum(n) => write!(f, "{}", n),
+            Constant::Integer(ref n) => write!(f, "{}", n),
+            Constant::Rational(ref n) => write!(f, "{}", n),
+            Constant::Float(ref n) => write!(f, "{}", n),
+            Constant::String(ref s) => write!(f, "\"{}\"", &s),
+            Constant::Usize(integer) => write!(f, "u{}", integer),
         }
     }
 }
@@ -549,7 +549,7 @@ impl PartialEq for Constant {
         match (self, other) {
             (&Constant::Atom(ref atom, _), &Constant::Char(c))
             | (&Constant::Char(c), &Constant::Atom(ref atom, _)) => {
-                atom.is_char() && Some(c) == atom.as_str().chars().next()
+                atom.is_char() && atom.as_str().starts_with(c)
             }
             (&Constant::Atom(ref a1, _), &Constant::Atom(ref a2, _)) => a1.as_str() == a2.as_str(),
             (&Constant::Char(c1), &Constant::Char(c2)) => c1 == c2,
@@ -565,7 +565,7 @@ impl PartialEq for Constant {
             (&Constant::Integer(ref n1), &Constant::Integer(ref n2)) => n1 == n2,
             (&Constant::Rational(ref n1), &Constant::Rational(ref n2)) => n1 == n2,
             (&Constant::Float(ref n1), &Constant::Float(ref n2)) => n1 == n2,
-            (&Constant::String(ref s1), &Constant::String(ref s2)) => &s1 == &s2,
+            (&Constant::String(ref s1), &Constant::String(ref s2)) => s1 == s2,
             (&Constant::EmptyList, &Constant::EmptyList) => true,
             (&Constant::Usize(u1), &Constant::Usize(u2)) => u1 == u2,
             _ => false,
@@ -632,7 +632,7 @@ impl ClauseName {
     #[inline]
     pub fn owning_module(&self) -> Self {
         match self {
-            &ClauseName::User(ref name) => {
+            ClauseName::User(ref name) => {
                 let module = name.owning_module();
                 ClauseName::User(TabledRc {
                     atom: module.clone(),
@@ -646,8 +646,8 @@ impl ClauseName {
     #[inline]
     pub fn to_rc(&self) -> Rc<String> {
         match self {
-            &ClauseName::BuiltIn(s) => Rc::new(s.to_string()),
-            &ClauseName::User(ref rc) => rc.inner(),
+            ClauseName::BuiltIn(s) => Rc::new(s.to_string()),
+            ClauseName::User(ref rc) => rc.inner(),
         }
     }
 
@@ -687,14 +687,14 @@ impl ClauseName {
     #[inline]
     pub fn as_str(&self) -> &str {
         match self {
-            &ClauseName::BuiltIn(s) => s,
-            &ClauseName::User(ref name) => name.as_ref(),
+            ClauseName::BuiltIn(s) => s,
+            ClauseName::User(ref name) => name.as_ref(),
         }
     }
 
     #[inline]
     pub fn is_char(&self) -> bool {
-        !self.as_str().is_empty() && self.as_str().chars().skip(1).next().is_none()
+        !self.as_str().is_empty() && self.as_str().chars().nth(1).is_none()
     }
 
     pub fn defrock_brackets(self) -> Self {
@@ -739,8 +739,8 @@ pub enum Term {
 impl Term {
     pub fn shared_op_desc(&self) -> Option<SharedOpDesc> {
         match self {
-            &Term::Clause(_, _, _, ref spec) => spec.clone(),
-            &Term::Constant(_, Constant::Atom(_, ref spec)) => spec.clone(),
+            Term::Clause(_, _, _, ref spec) => spec.clone(),
+            Term::Constant(_, Constant::Atom(_, ref spec)) => spec.clone(),
             _ => None,
         }
     }
@@ -754,7 +754,7 @@ impl Term {
 
     pub fn first_arg(&self) -> Option<&Term> {
         match self {
-            &Term::Clause(_, _, ref terms, _) => terms.first().map(|bt| bt.as_ref()),
+            Term::Clause(_, _, ref terms, _) => terms.first().map(|bt| bt.as_ref()),
             _ => None,
         }
     }
@@ -780,14 +780,14 @@ impl Term {
 
     pub fn arity(&self) -> usize {
         match self {
-            &Term::Clause(_, _, ref child_terms, ..) => child_terms.len(),
+            Term::Clause(_, _, ref child_terms, ..) => child_terms.len(),
             _ => 0,
         }
     }
 }
 
 fn unfold_by_str_once(term: &mut Term, s: &str) -> Option<(Term, Term)> {
-    if let &mut Term::Clause(_, ref name, ref mut subterms, _) = term {
+    if let Term::Clause(_, ref name, ref mut subterms, _) = term {
         if name.as_str() == s && subterms.len() == 2 {
             let snd = *subterms.pop().unwrap();
             let fst = *subterms.pop().unwrap();
index aff75d23551337375cdae5a90ef5b62bce6f944c..75a3a91e176aaf1eec412f7b9091008d7942ed28 100644 (file)
@@ -517,7 +517,7 @@ impl<'a, R: Read> Lexer<'a, R> {
             if single_quote_char!(self.lookahead_char()?) {
                 self.skip_char()?;
 
-                if !token.is_empty() && token.chars().skip(1).next().is_none() {
+                if !token.is_empty() && token.chars().nth(1).is_none() {
                     if let Some(c) = token.chars().next() {
                         return Ok(Token::Constant(Constant::Char(c)));
                     }
@@ -713,7 +713,7 @@ impl<'a, R: Read> Lexer<'a, R> {
                     }
 
                     self.get_single_quoted_char()
-                        .and_then(|c| Ok(Token::Constant(Constant::Fixnum(c as isize))))
+                        .map(|c| Token::Constant(Constant::Fixnum(c as isize)))
                         .or_else(|_| {
                             self.return_char(c);
 
index 87785daa6f7fa963c3ec9902af17f25221473f88..4ff09eb63091926296c1f636ea38a193d6e22de7 100644 (file)
@@ -484,7 +484,7 @@ impl<'a, R: Read> Parser<'a, R> {
             if self.atomize_term(&self.terms[idx - 1]).is_some() {
                 self.stack.truncate(stack_len + 1);
 
-                let mut subterms: Vec<_> = self.terms.drain(idx..).map(|t| Box::new(t)).collect();
+                let mut subterms: Vec<_> = self.terms.drain(idx..).map(Box::new).collect();
 
                 if let Some(name) = self.terms.pop().and_then(|t| self.atomize_term(&t)) {
                     // reduce the '.' functor to a cons cell if it applies.
@@ -722,25 +722,24 @@ impl<'a, R: Read> Parser<'a, R> {
 
         let idx = self.stack.len() - 2;
 
-        match self.stack.remove(idx) {
-            td => match td.tt {
-                TokenType::Open | TokenType::OpenCT => {
-                    if self.stack[idx].tt == TokenType::Comma {
-                        return false;
-                    }
-
-                    if let Some(atom) = sep_to_atom(self.stack[idx].tt) {
-                        self.terms
-                            .push(Term::Constant(Cell::default(), Constant::Atom(atom, None)));
-                    }
+        let td = self.stack.remove(idx);
+        match td.tt {
+            TokenType::Open | TokenType::OpenCT => {
+                if self.stack[idx].tt == TokenType::Comma {
+                    return false;
+                }
 
-                    self.stack[idx].spec = TERM;
-                    self.stack[idx].tt = TokenType::Term;
-                    self.stack[idx].priority = 0;
-                    true
+                if let Some(atom) = sep_to_atom(self.stack[idx].tt) {
+                    self.terms
+                        .push(Term::Constant(Cell::default(), Constant::Atom(atom, None)));
                 }
-                _ => false,
-            },
+
+                self.stack[idx].spec = TERM;
+                self.stack[idx].tt = TokenType::Term;
+                self.stack[idx].priority = 0;
+                true
+            }
+            _ => false,
         }
     }
 
@@ -756,7 +755,7 @@ impl<'a, R: Read> Parser<'a, R> {
                 match self.tokens.last().ok_or(ParserError::UnexpectedEOF)? {
                     // do this when layout hasn't been inserted,
                     // ie. why we don't match on Token::Open.
-                    &Token::OpenCT => {
+                    Token::OpenCT => {
                         // can't be prefix, so either inf == 0
                         // or post == 0.
                         self.reduce_op(inf + post);
@@ -831,16 +830,16 @@ impl<'a, R: Read> Parser<'a, R> {
 
     fn atomize_term(&self, term: &Term) -> Option<ClauseName> {
         match term {
-            &Term::Constant(_, ref c) => self.atomize_constant(c),
+            Term::Constant(_, ref c) => self.atomize_constant(c),
             _ => None,
         }
     }
 
     fn atomize_constant(&self, c: &Constant) -> Option<ClauseName> {
         match c {
-            &Constant::Atom(ref name, _) => Some(name.clone()),
-            &Constant::Char(c) => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
-            &Constant::EmptyList => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
+            Constant::Atom(ref name, _) => Some(name.clone()),
+            Constant::Char(c) => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
+            Constant::EmptyList => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
             _ => None,
         }
     }
@@ -892,7 +891,7 @@ impl<'a, R: Read> Parser<'a, R> {
                 self.negate_number(n, negate_rc, Constant::Rational)
             }
             Token::Constant(Constant::Float(n)) => {
-                self.negate_number(n, |n| OrderedFloat(-n.into_inner()), |n| Constant::Float(n))
+                self.negate_number(n, |n| OrderedFloat(-n.into_inner()), Constant::Float)
             }
             Token::Constant(c) => {
                 if let Some(name) = self.atomize_constant(&c) {
index 8fcf4b86e7219dc5a0428eed61e6b9c6f130064f..47f87d3028422921da3d7e39f996367ed83bff10 100644 (file)
@@ -104,7 +104,7 @@ impl<T: Hash + Eq> Hash for TabledRc<T> {
 impl<T: Hash + Eq + ToString> TabledRc<T> {
     pub fn new(atom: T, table: TabledData<T>) -> Self {
         let atom = match table.borrow_mut().take(&atom) {
-            Some(atom) => atom.clone(),
+            Some(atom) => atom,
             None => Rc::new(atom),
         };