From 17c79cd98d47655450d979dbe854d1e2ce88011b Mon Sep 17 00:00:00 2001 From: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> Date: Tue, 19 Dec 2023 09:02:46 +0400 Subject: [PATCH 1/4] chore: Bump Rust toolchain --- .github/workflows/rust.yml | 8 ++++---- rust-toolchain | 1 - rust-toolchain.toml | 4 ++++ 3 files changed, 8 insertions(+), 5 deletions(-) delete mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4a326d21e..3f4c5d524 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ jobs: uses: hecrj/setup-rust-action@v1 with: components: rustfmt - rust-version: nightly-2022-03-22 + rust-version: nightly-2023-12-13 - uses: actions/checkout@v2 - run: cargo fmt -- --check --config-path <(echo 'license_template_path = "HEADER"') @@ -22,7 +22,7 @@ jobs: uses: hecrj/setup-rust-action@v1 with: components: clippy - rust-version: nightly-2022-03-22 + rust-version: nightly-2023-12-13 - uses: actions/checkout@v2 - run: cargo clippy --all-targets --all-features -- -D warnings @@ -41,14 +41,14 @@ jobs: uses: hecrj/setup-rust-action@v1 with: targets: 'thumbv6m-none-eabi' - rust-version: nightly-2022-03-22 + rust-version: nightly-2023-12-13 - uses: actions/checkout@master - run: cargo check --no-default-features --target thumbv6m-none-eabi test: strategy: matrix: - rust: [stable, beta, nightly, nightly-2022-03-22] + rust: [stable, beta, nightly, nightly-2023-12-13] runs-on: ubuntu-latest steps: - name: Setup Rust diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 181ead84c..000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2022-03-22 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..c7a2040f8 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2023-12-13" +components = ["rustfmt", "rustc-dev", "clippy"] +profile = "minimal" From 2f2a69eb470a5c20f348dbd79e182153eca641c4 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Fri, 7 Oct 2022 22:41:33 +0200 Subject: [PATCH 2/4] clippy fixes (#656) --- src/tokenizer.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index f9a4e40cf..e78bee62c 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -214,7 +214,7 @@ impl Token { Token::Word(Word { value: word.to_string(), quote_style, - keyword: if quote_style == None { + keyword: if quote_style.is_none() { let keyword = ALL_KEYWORDS.binary_search(&word_uppercase.as_str()); keyword.map_or(Keyword::NoKeyword, |x| ALL_KEYWORDS_INDEX[x]) } else { @@ -339,8 +339,12 @@ impl<'a> Tokenizer<'a> { } Token::Whitespace(Whitespace::Tab) => self.col += 4, - Token::Word(w) if w.quote_style == None => self.col += w.value.len() as u64, - Token::Word(w) if w.quote_style != None => self.col += w.value.len() as u64 + 2, + Token::Word(w) => { + self.col += w.value.len() as u64; + if w.quote_style.is_some() { + self.col += 2; + } + } Token::Number(s, _) => self.col += s.len() as u64, Token::SingleQuotedString(s) => self.col += s.len() as u64, Token::Placeholder(s) => self.col += s.len() as u64, From 1e193215571e640419d47816f6c277f5d73b3fd6 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 5 Oct 2023 15:25:03 -0400 Subject: [PATCH 3/4] Fix for clippy 1.73 (#995) --- src/ast/mod.rs | 2 +- src/parser.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index feec8bda1..abe5e5577 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -140,7 +140,7 @@ impl fmt::Display for Ident { } f.write_char(q) } - Some(q) if q == '[' => write!(f, "[{}]", self.value), + Some('[') => write!(f, "[{}]", self.value), None => f.write_str(&self.value), _ => panic!("unexpected quote style"), } diff --git a/src/parser.rs b/src/parser.rs index bd0946a24..1106ae061 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2919,7 +2919,11 @@ impl<'a> Parser<'a> { /// Parse a literal string pub fn parse_literal_string(&mut self) -> Result { match self.next_token() { - Token::Word(Word { value, keyword, .. }) if keyword == Keyword::NoKeyword => Ok(value), + Token::Word(Word { + value, + keyword: Keyword::NoKeyword, + .. + }) => Ok(value), Token::SingleQuotedString(s) => Ok(s), Token::EscapedStringLiteral(s) if dialect_of!(self is PostgreSqlDialect | GenericDialect) => { Ok(s) From 01f890295ed4bf5bff8fe8d3787c969d3169c546 Mon Sep 17 00:00:00 2001 From: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> Date: Tue, 19 Dec 2023 09:10:51 +0400 Subject: [PATCH 4/4] chore: Fix clippy issues --- src/ast/mod.rs | 2 +- src/dialect/ansi.rs | 7 ++----- src/dialect/clickhouse.rs | 4 ++-- src/dialect/generic.rs | 12 ++++-------- src/dialect/hive.rs | 11 ++++------- src/dialect/mssql.rs | 12 ++++-------- src/dialect/mysql.rs | 6 +++--- src/dialect/postgresql.rs | 8 ++++---- src/dialect/snowflake.rs | 8 ++++---- src/dialect/sqlite.rs | 6 +++--- src/parser.rs | 8 +------- src/tokenizer.rs | 11 ++++------- tests/sqlparser_mysql.rs | 2 +- tests/sqlparser_postgres.rs | 2 -- 14 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index abe5e5577..69791c01b 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -1786,7 +1786,7 @@ impl fmt::Display for Statement { Statement::SetVariable { key_values } => { f.write_str("SET ")?; - if let Some(key_value) = key_values.get(0) { + if let Some(key_value) = key_values.first() { if key_value.hivevar { let values: Vec = key_value .value diff --git a/src/dialect/ansi.rs b/src/dialect/ansi.rs index 1015ca2d3..14c83ae16 100644 --- a/src/dialect/ansi.rs +++ b/src/dialect/ansi.rs @@ -17,13 +17,10 @@ pub struct AnsiDialect {} impl Dialect for AnsiDialect { fn is_identifier_start(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() } fn is_identifier_part(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) - || ch == '_' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '_' } } diff --git a/src/dialect/clickhouse.rs b/src/dialect/clickhouse.rs index 24ec5e49f..395116f9c 100644 --- a/src/dialect/clickhouse.rs +++ b/src/dialect/clickhouse.rs @@ -18,10 +18,10 @@ pub struct ClickHouseDialect {} impl Dialect for ClickHouseDialect { fn is_identifier_start(&self, ch: char) -> bool { // See https://clickhouse.com/docs/en/sql-reference/syntax/#syntax-identifiers - ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' } fn is_identifier_part(&self, ch: char) -> bool { - self.is_identifier_start(ch) || ('0'..='9').contains(&ch) + self.is_identifier_start(ch) || ch.is_ascii_digit() } } diff --git a/src/dialect/generic.rs b/src/dialect/generic.rs index 818fa0d0a..51ae3dafd 100644 --- a/src/dialect/generic.rs +++ b/src/dialect/generic.rs @@ -17,17 +17,13 @@ pub struct GenericDialect; impl Dialect for GenericDialect { fn is_identifier_start(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ch == '_' - || ch == '#' - || ch == '@' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch == '#' || ch == '@' } fn is_identifier_part(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '@' || ch == '$' || ch == '#' diff --git a/src/dialect/hive.rs b/src/dialect/hive.rs index 9b42857ec..7db599f3d 100644 --- a/src/dialect/hive.rs +++ b/src/dialect/hive.rs @@ -21,16 +21,13 @@ impl Dialect for HiveDialect { } fn is_identifier_start(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) - || ch == '$' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '$' } fn is_identifier_part(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '_' || ch == '$' || ch == '{' diff --git a/src/dialect/mssql.rs b/src/dialect/mssql.rs index 539a17a9f..682376b17 100644 --- a/src/dialect/mssql.rs +++ b/src/dialect/mssql.rs @@ -23,17 +23,13 @@ impl Dialect for MsSqlDialect { fn is_identifier_start(&self, ch: char) -> bool { // See https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-2017#rules-for-regular-identifiers // We don't support non-latin "letters" currently. - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ch == '_' - || ch == '#' - || ch == '@' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch == '#' || ch == '@' } fn is_identifier_part(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '@' || ch == '$' || ch == '#' diff --git a/src/dialect/mysql.rs b/src/dialect/mysql.rs index d6095262c..441b2c240 100644 --- a/src/dialect/mysql.rs +++ b/src/dialect/mysql.rs @@ -20,8 +20,8 @@ impl Dialect for MySqlDialect { // See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html. // We don't yet support identifiers beginning with numbers, as that // makes it hard to distinguish numeric literals. - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() || ch == '_' || ch == '$' || ch == '@' @@ -29,7 +29,7 @@ impl Dialect for MySqlDialect { } fn is_identifier_part(&self, ch: char) -> bool { - self.is_identifier_start(ch) || ('0'..='9').contains(&ch) + self.is_identifier_start(ch) || ch.is_ascii_digit() } fn is_delimited_identifier_start(&self, ch: char) -> bool { diff --git a/src/dialect/postgresql.rs b/src/dialect/postgresql.rs index 0c2eb99f0..3534d2942 100644 --- a/src/dialect/postgresql.rs +++ b/src/dialect/postgresql.rs @@ -20,13 +20,13 @@ impl Dialect for PostgreSqlDialect { // See https://www.postgresql.org/docs/11/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS // We don't yet support identifiers beginning with "letters with // diacritical marks and non-Latin letters" - ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' } fn is_identifier_part(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '$' || ch == '_' } diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index 11108e973..4fc8de735 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -18,13 +18,13 @@ pub struct SnowflakeDialect; impl Dialect for SnowflakeDialect { // see https://docs.snowflake.com/en/sql-reference/identifiers-syntax.html fn is_identifier_start(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' } fn is_identifier_part(&self, ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '$' || ch == '_' } diff --git a/src/dialect/sqlite.rs b/src/dialect/sqlite.rs index 4ce2f834b..ed6426d9e 100644 --- a/src/dialect/sqlite.rs +++ b/src/dialect/sqlite.rs @@ -25,14 +25,14 @@ impl Dialect for SQLiteDialect { fn is_identifier_start(&self, ch: char) -> bool { // See https://www.sqlite.org/draft/tokenreq.html - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() || ch == '_' || ch == '$' || ('\u{007f}'..='\u{ffff}').contains(&ch) } fn is_identifier_part(&self, ch: char) -> bool { - self.is_identifier_start(ch) || ('0'..='9').contains(&ch) + self.is_identifier_start(ch) || ch.is_ascii_digit() } } diff --git a/src/parser.rs b/src/parser.rs index 1106ae061..5a8682f6c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3827,13 +3827,7 @@ impl<'a> Parser<'a> { None }; let object_name = match db_name { - Some(db_name) => ObjectName( - db_name - .0 - .into_iter() - .chain(table_name.0.into_iter()) - .collect(), - ), + Some(db_name) => ObjectName(db_name.0.into_iter().chain(table_name.0).collect()), None => table_name, }; let filter = self.parse_show_statement_filter()?; diff --git a/src/tokenizer.rs b/src/tokenizer.rs index e78bee62c..8f4b9c05d 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -424,7 +424,7 @@ impl<'a> Tokenizer<'a> { chars.next(); // consume the first char let s = self.tokenize_word(ch, chars); - if s.chars().all(|x| ('0'..='9').contains(&x) || x == '.') { + if s.chars().all(|x| x.is_ascii_digit() || x == '.') { let mut s = peeking_take_while(&mut s.chars().peekable(), |ch| { matches!(ch, '0'..='9' | '.') }); @@ -462,15 +462,12 @@ impl<'a> Tokenizer<'a> { } // numbers and period '0'..='9' | '.' => { - let mut s = peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + let mut s = peeking_take_while(chars, |ch| ch.is_ascii_digit()); // match binary literal that starts with 0x if s == "0" && chars.peek() == Some(&'x') { chars.next(); - let s2 = peeking_take_while( - chars, - |ch| matches!(ch, '0'..='9' | 'A'..='F' | 'a'..='f'), - ); + let s2 = peeking_take_while(chars, |ch| ch.is_ascii_hexdigit()); return Ok(Some(Token::HexStringLiteral(s2))); } @@ -479,7 +476,7 @@ impl<'a> Tokenizer<'a> { s.push('.'); chars.next(); } - s += &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + s += &peeking_take_while(chars, |ch| ch.is_ascii_digit()); // No number -> Token::Period if s == "." { diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs index c3204f156..130aa7906 100644 --- a/tests/sqlparser_mysql.rs +++ b/tests/sqlparser_mysql.rs @@ -498,7 +498,7 @@ fn parse_escaped_string() { let sql = r#"SELECT 'I''m fine'"#; let projection = mysql().verified_only_select(sql).projection; - let item = projection.get(0).unwrap(); + let item = projection.first().unwrap(); match &item { SelectItem::UnnamedExpr(Expr::Value(value)) => { diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 88fd4c008..117f9ff30 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -1182,12 +1182,10 @@ fn parse_pg_regex_match_ops() { fn parse_array_index_expr() { #[cfg(feature = "bigdecimal")] let num: Vec = (0..=10) - .into_iter() .map(|s| Expr::Value(Value::Number(bigdecimal::BigDecimal::from(s), false))) .collect(); #[cfg(not(feature = "bigdecimal"))] let num: Vec = (0..=10) - .into_iter() .map(|s| Expr::Value(Value::Number(s.to_string(), false))) .collect();