Skip to content

Commit ba97802

Browse files
committed
chore: Fix clippy issues
1 parent 1e19321 commit ba97802

14 files changed

+37
-61
lines changed

src/ast/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ impl fmt::Display for Statement {
17861786
Statement::SetVariable { key_values } => {
17871787
f.write_str("SET ")?;
17881788

1789-
if let Some(key_value) = key_values.get(0) {
1789+
if let Some(key_value) = key_values.first() {
17901790
if key_value.hivevar {
17911791
let values: Vec<String> = key_value
17921792
.value

src/dialect/ansi.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ pub struct AnsiDialect {}
1717

1818
impl Dialect for AnsiDialect {
1919
fn is_identifier_start(&self, ch: char) -> bool {
20-
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch)
20+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase()
2121
}
2222

2323
fn is_identifier_part(&self, ch: char) -> bool {
24-
('a'..='z').contains(&ch)
25-
|| ('A'..='Z').contains(&ch)
26-
|| ('0'..='9').contains(&ch)
27-
|| ch == '_'
24+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '_'
2825
}
2926
}

src/dialect/clickhouse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub struct ClickHouseDialect {}
1818
impl Dialect for ClickHouseDialect {
1919
fn is_identifier_start(&self, ch: char) -> bool {
2020
// See https://clickhouse.com/docs/en/sql-reference/syntax/#syntax-identifiers
21-
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_'
21+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_'
2222
}
2323

2424
fn is_identifier_part(&self, ch: char) -> bool {
25-
self.is_identifier_start(ch) || ('0'..='9').contains(&ch)
25+
self.is_identifier_start(ch) || ch.is_ascii_digit()
2626
}
2727
}

src/dialect/generic.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ pub struct GenericDialect;
1717

1818
impl Dialect for GenericDialect {
1919
fn is_identifier_start(&self, ch: char) -> bool {
20-
('a'..='z').contains(&ch)
21-
|| ('A'..='Z').contains(&ch)
22-
|| ch == '_'
23-
|| ch == '#'
24-
|| ch == '@'
20+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch == '#' || ch == '@'
2521
}
2622

2723
fn is_identifier_part(&self, ch: char) -> bool {
28-
('a'..='z').contains(&ch)
29-
|| ('A'..='Z').contains(&ch)
30-
|| ('0'..='9').contains(&ch)
24+
ch.is_ascii_lowercase()
25+
|| ch.is_ascii_uppercase()
26+
|| ch.is_ascii_digit()
3127
|| ch == '@'
3228
|| ch == '$'
3329
|| ch == '#'

src/dialect/hive.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ impl Dialect for HiveDialect {
2121
}
2222

2323
fn is_identifier_start(&self, ch: char) -> bool {
24-
('a'..='z').contains(&ch)
25-
|| ('A'..='Z').contains(&ch)
26-
|| ('0'..='9').contains(&ch)
27-
|| ch == '$'
24+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '$'
2825
}
2926

3027
fn is_identifier_part(&self, ch: char) -> bool {
31-
('a'..='z').contains(&ch)
32-
|| ('A'..='Z').contains(&ch)
33-
|| ('0'..='9').contains(&ch)
28+
ch.is_ascii_lowercase()
29+
|| ch.is_ascii_uppercase()
30+
|| ch.is_ascii_digit()
3431
|| ch == '_'
3532
|| ch == '$'
3633
|| ch == '{'

src/dialect/mssql.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ impl Dialect for MsSqlDialect {
2323
fn is_identifier_start(&self, ch: char) -> bool {
2424
// See https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-2017#rules-for-regular-identifiers
2525
// We don't support non-latin "letters" currently.
26-
('a'..='z').contains(&ch)
27-
|| ('A'..='Z').contains(&ch)
28-
|| ch == '_'
29-
|| ch == '#'
30-
|| ch == '@'
26+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch == '#' || ch == '@'
3127
}
3228

3329
fn is_identifier_part(&self, ch: char) -> bool {
34-
('a'..='z').contains(&ch)
35-
|| ('A'..='Z').contains(&ch)
36-
|| ('0'..='9').contains(&ch)
30+
ch.is_ascii_lowercase()
31+
|| ch.is_ascii_uppercase()
32+
|| ch.is_ascii_digit()
3733
|| ch == '@'
3834
|| ch == '$'
3935
|| ch == '#'

src/dialect/mysql.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ impl Dialect for MySqlDialect {
2020
// See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html.
2121
// We don't yet support identifiers beginning with numbers, as that
2222
// makes it hard to distinguish numeric literals.
23-
('a'..='z').contains(&ch)
24-
|| ('A'..='Z').contains(&ch)
23+
ch.is_ascii_lowercase()
24+
|| ch.is_ascii_uppercase()
2525
|| ch == '_'
2626
|| ch == '$'
2727
|| ch == '@'
2828
|| ('\u{0080}'..='\u{ffff}').contains(&ch)
2929
}
3030

3131
fn is_identifier_part(&self, ch: char) -> bool {
32-
self.is_identifier_start(ch) || ('0'..='9').contains(&ch)
32+
self.is_identifier_start(ch) || ch.is_ascii_digit()
3333
}
3434

3535
fn is_delimited_identifier_start(&self, ch: char) -> bool {

src/dialect/postgresql.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ impl Dialect for PostgreSqlDialect {
2020
// See https://www.postgresql.org/docs/11/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
2121
// We don't yet support identifiers beginning with "letters with
2222
// diacritical marks and non-Latin letters"
23-
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_'
23+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_'
2424
}
2525

2626
fn is_identifier_part(&self, ch: char) -> bool {
27-
('a'..='z').contains(&ch)
28-
|| ('A'..='Z').contains(&ch)
29-
|| ('0'..='9').contains(&ch)
27+
ch.is_ascii_lowercase()
28+
|| ch.is_ascii_uppercase()
29+
|| ch.is_ascii_digit()
3030
|| ch == '$'
3131
|| ch == '_'
3232
}

src/dialect/snowflake.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ pub struct SnowflakeDialect;
1818
impl Dialect for SnowflakeDialect {
1919
// see https://docs.snowflake.com/en/sql-reference/identifiers-syntax.html
2020
fn is_identifier_start(&self, ch: char) -> bool {
21-
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_'
21+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_'
2222
}
2323

2424
fn is_identifier_part(&self, ch: char) -> bool {
25-
('a'..='z').contains(&ch)
26-
|| ('A'..='Z').contains(&ch)
27-
|| ('0'..='9').contains(&ch)
25+
ch.is_ascii_lowercase()
26+
|| ch.is_ascii_uppercase()
27+
|| ch.is_ascii_digit()
2828
|| ch == '$'
2929
|| ch == '_'
3030
}

src/dialect/sqlite.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ impl Dialect for SQLiteDialect {
2525

2626
fn is_identifier_start(&self, ch: char) -> bool {
2727
// See https://www.sqlite.org/draft/tokenreq.html
28-
('a'..='z').contains(&ch)
29-
|| ('A'..='Z').contains(&ch)
28+
ch.is_ascii_lowercase()
29+
|| ch.is_ascii_uppercase()
3030
|| ch == '_'
3131
|| ch == '$'
3232
|| ('\u{007f}'..='\u{ffff}').contains(&ch)
3333
}
3434

3535
fn is_identifier_part(&self, ch: char) -> bool {
36-
self.is_identifier_start(ch) || ('0'..='9').contains(&ch)
36+
self.is_identifier_start(ch) || ch.is_ascii_digit()
3737
}
3838
}

src/parser.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -3827,13 +3827,7 @@ impl<'a> Parser<'a> {
38273827
None
38283828
};
38293829
let object_name = match db_name {
3830-
Some(db_name) => ObjectName(
3831-
db_name
3832-
.0
3833-
.into_iter()
3834-
.chain(table_name.0.into_iter())
3835-
.collect(),
3836-
),
3830+
Some(db_name) => ObjectName(db_name.0.into_iter().chain(table_name.0).collect()),
38373831
None => table_name,
38383832
};
38393833
let filter = self.parse_show_statement_filter()?;

src/tokenizer.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'a> Tokenizer<'a> {
424424
chars.next(); // consume the first char
425425
let s = self.tokenize_word(ch, chars);
426426

427-
if s.chars().all(|x| ('0'..='9').contains(&x) || x == '.') {
427+
if s.chars().all(|x| x.is_ascii_digit() || x == '.') {
428428
let mut s = peeking_take_while(&mut s.chars().peekable(), |ch| {
429429
matches!(ch, '0'..='9' | '.')
430430
});
@@ -462,15 +462,12 @@ impl<'a> Tokenizer<'a> {
462462
}
463463
// numbers and period
464464
'0'..='9' | '.' => {
465-
let mut s = peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
465+
let mut s = peeking_take_while(chars, |ch| ch.is_ascii_digit());
466466

467467
// match binary literal that starts with 0x
468468
if s == "0" && chars.peek() == Some(&'x') {
469469
chars.next();
470-
let s2 = peeking_take_while(
471-
chars,
472-
|ch| matches!(ch, '0'..='9' | 'A'..='F' | 'a'..='f'),
473-
);
470+
let s2 = peeking_take_while(chars, |ch| ch.is_ascii_hexdigit());
474471
return Ok(Some(Token::HexStringLiteral(s2)));
475472
}
476473

@@ -479,7 +476,7 @@ impl<'a> Tokenizer<'a> {
479476
s.push('.');
480477
chars.next();
481478
}
482-
s += &peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
479+
s += &peeking_take_while(chars, |ch| ch.is_ascii_digit());
483480

484481
// No number -> Token::Period
485482
if s == "." {

tests/sqlparser_mysql.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn parse_escaped_string() {
498498
let sql = r#"SELECT 'I''m fine'"#;
499499

500500
let projection = mysql().verified_only_select(sql).projection;
501-
let item = projection.get(0).unwrap();
501+
let item = projection.first().unwrap();
502502

503503
match &item {
504504
SelectItem::UnnamedExpr(Expr::Value(value)) => {

tests/sqlparser_postgres.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,6 @@ fn parse_array_index_expr() {
11871187
.collect();
11881188
#[cfg(not(feature = "bigdecimal"))]
11891189
let num: Vec<Expr> = (0..=10)
1190-
.into_iter()
11911190
.map(|s| Expr::Value(Value::Number(s.to_string(), false)))
11921191
.collect();
11931192

0 commit comments

Comments
 (0)