From 1047c280b045feb57a38afed6ba946e4f1bfa2c8 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Fri, 16 May 2025 22:29:43 +0200 Subject: [PATCH 1/3] fix new rust 1.87 cargo clippy warnings --- src/ast/visitor.rs | 3 ++- src/parser/mod.rs | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ast/visitor.rs b/src/ast/visitor.rs index 50985a3e7b..2d867b6956 100644 --- a/src/ast/visitor.rs +++ b/src/ast/visitor.rs @@ -977,7 +977,8 @@ mod visit_mut_tests { .parse_statement() .unwrap(); - s.visit(visitor); + let flow = s.visit(visitor); + assert_eq!(flow, ControlFlow::Continue(())); s } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 838996130b..b7ac3562bd 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -2558,9 +2558,7 @@ impl<'a> Parser<'a> { self.expect_token(&Token::LParen)?; let mut trim_where = None; if let Token::Word(word) = self.peek_token().token { - if [Keyword::BOTH, Keyword::LEADING, Keyword::TRAILING] - .iter() - .any(|d| word.keyword == *d) + if [Keyword::BOTH, Keyword::LEADING, Keyword::TRAILING].contains(&word.keyword) { trim_where = Some(self.parse_trim_where()?); } From 96dbea8303e84cad5a37b5ce9680487cf5a9137a Mon Sep 17 00:00:00 2001 From: lovasoa Date: Fri, 16 May 2025 22:40:05 +0200 Subject: [PATCH 2/3] allow large enum variants https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant --- src/ast/visitor.rs | 10 ++++++---- src/lib.rs | 3 +++ src/parser/mod.rs | 3 +-- tests/sqlparser_common.rs | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ast/visitor.rs b/src/ast/visitor.rs index 2d867b6956..ab4f73aa46 100644 --- a/src/ast/visitor.rs +++ b/src/ast/visitor.rs @@ -741,7 +741,7 @@ mod tests { } } - fn do_visit(sql: &str, visitor: &mut V) -> Statement { + fn do_visit>(sql: &str, visitor: &mut V) -> Statement { let dialect = GenericDialect {}; let tokens = Tokenizer::new(&dialect, sql).tokenize().unwrap(); let s = Parser::new(&dialect) @@ -749,7 +749,8 @@ mod tests { .parse_statement() .unwrap(); - s.visit(visitor); + let flow = s.visit(visitor); + assert_eq!(flow, ControlFlow::Continue(())); s } @@ -938,7 +939,8 @@ mod tests { .unwrap(); let mut visitor = QuickVisitor {}; - s.visit(&mut visitor); + let flow = s.visit(&mut visitor); + assert_eq!(flow, ControlFlow::Continue(())); } } @@ -969,7 +971,7 @@ mod visit_mut_tests { } } - fn do_visit_mut(sql: &str, visitor: &mut V) -> Statement { + fn do_visit_mut>(sql: &str, visitor: &mut V) -> Statement { let dialect = GenericDialect {}; let tokens = Tokenizer::new(&dialect, sql).tokenize().unwrap(); let mut s = Parser::new(&dialect) diff --git a/src/lib.rs b/src/lib.rs index c81ab50023..e0df27896f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,6 +149,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::upper_case_acronyms)] +// The AST represents rich AST nodes, +// and favors expressiveness and ease of use over speed and memory usage. +#![allow(clippy::large_enum_variant)] // Allow proc-macros to find this crate extern crate self as sqlparser; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index b7ac3562bd..992d19c496 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -2558,8 +2558,7 @@ impl<'a> Parser<'a> { self.expect_token(&Token::LParen)?; let mut trim_where = None; if let Token::Word(word) = self.peek_token().token { - if [Keyword::BOTH, Keyword::LEADING, Keyword::TRAILING].contains(&word.keyword) - { + if [Keyword::BOTH, Keyword::LEADING, Keyword::TRAILING].contains(&word.keyword) { trim_where = Some(self.parse_trim_where()?); } } diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 8e3bc00217..86c473d7d0 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -14346,7 +14346,7 @@ fn test_visit_order() { let sql = "SELECT CASE a WHEN 1 THEN 2 WHEN 3 THEN 4 ELSE 5 END"; let stmt = verified_stmt(sql); let mut visited = vec![]; - sqlparser::ast::visit_expressions(&stmt, |expr| { + let _ = sqlparser::ast::visit_expressions(&stmt, |expr| { visited.push(expr.to_string()); core::ops::ControlFlow::<()>::Continue(()) }); From b53daee0cade54b70e6605e0b68c73aa2986c399 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Fri, 16 May 2025 22:44:16 +0200 Subject: [PATCH 3/3] better comment --- src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e0df27896f..dbfd1791a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,8 +149,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::upper_case_acronyms)] -// The AST represents rich AST nodes, -// and favors expressiveness and ease of use over speed and memory usage. +// Permit large enum variants to keep a unified, expressive AST. +// Splitting complex nodes (expressions, statements, types) into separate types +// would bloat the API and hide intent. Extra memory is a worthwhile tradeoff. #![allow(clippy::large_enum_variant)] // Allow proc-macros to find this crate