Skip to content

feat: use edition 2024 #1736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include = [
"Cargo.toml",
"LICENSE.TXT",
]
edition = "2021"
edition = "2024"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only concern is if this will force users of slparser to use newer versions of the rust compiler (as in once we release sqlparser with this change, will it require the use of rust 1.85?)

I haven't studied the implications yet


[lib]
name = "sqlparser"
Expand Down
8 changes: 4 additions & 4 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ impl fmt::Display for Statement {
local = if *local { " LOCAL" } else { "" },
path = path
)?;
if let Some(ref ff) = file_format {
if let Some(ff) = file_format {
write!(f, " STORED AS {ff}")?
}
write!(f, " {source}")
Expand Down Expand Up @@ -3760,7 +3760,7 @@ impl fmt::Display for Statement {
}
}

if let Some(ref parts) = partitions {
if let Some(parts) = partitions {
if !parts.is_empty() {
write!(f, " PARTITION ({})", display_comma_separated(parts))?;
}
Expand Down Expand Up @@ -3827,7 +3827,7 @@ impl fmt::Display for Statement {
"ANALYZE{}{table_name}",
if *has_table_keyword { " TABLE " } else { " " }
)?;
if let Some(ref parts) = partitions {
if let Some(parts) = partitions {
if !parts.is_empty() {
write!(f, " PARTITION ({})", display_comma_separated(parts))?;
}
Expand Down Expand Up @@ -4149,7 +4149,7 @@ impl fmt::Display for Statement {
overwrite = if *overwrite { "OVERWRITE " } else { "" },
table_name = table_name,
)?;
if let Some(ref parts) = &partitioned {
if let Some(parts) = &partitioned {
if !parts.is_empty() {
write!(f, " PARTITION ({})", display_comma_separated(parts))?;
}
Expand Down
4 changes: 2 additions & 2 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use sqlparser_derive::{Visit, VisitMut};
/// Defines a string constant for a single keyword: `kw_def!(SELECT);`
/// expands to `pub const SELECT = "SELECT";`
macro_rules! kw_def {
($ident:ident = $string_keyword:expr) => {
($ident:ident = $string_keyword:expr_2021) => {
pub const $ident: &'static str = $string_keyword;
};
($ident:ident) => {
Expand All @@ -48,7 +48,7 @@ macro_rules! kw_def {
/// and defines an ALL_KEYWORDS array of the defined constants.
macro_rules! define_keywords {
($(
$ident:ident $(= $string_keyword:expr)?
$ident:ident $(= $string_keyword:expr_2021)?
),*) => {
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down
10 changes: 5 additions & 5 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum ParserError {

// Use `Parser::expected` instead, if possible
macro_rules! parser_err {
($MSG:expr, $loc:expr) => {
($MSG:expr_2021, $loc:expr_2021) => {
Err(ParserError::ParserError(format!("{}{}", $MSG, $loc)))
};
}
Expand Down Expand Up @@ -14727,7 +14727,7 @@ mod tests {
use crate::test_utils::TestedDialects;

macro_rules! test_parse_data_type {
($dialect:expr, $input:expr, $expected_type:expr $(,)?) => {{
($dialect:expr_2021, $input:expr_2021, $expected_type:expr_2021 $(,)?) => {{
$dialect.run_parser_method(&*$input, |parser| {
let data_type = parser.parse_data_type().unwrap();
assert_eq!($expected_type, data_type);
Expand Down Expand Up @@ -15045,7 +15045,7 @@ mod tests {
fn test_parse_schema_name() {
// The expected name should be identical as the input name, that's why I don't receive both
macro_rules! test_parse_schema_name {
($input:expr, $expected_name:expr $(,)?) => {{
($input:expr_2021, $expected_name:expr_2021 $(,)?) => {{
all_dialects().run_parser_method(&*$input, |parser| {
let schema_name = parser.parse_schema_name().unwrap();
// Validate that the structure is the same as expected
Expand Down Expand Up @@ -15077,7 +15077,7 @@ mod tests {
#[test]
fn mysql_parse_index_table_constraint() {
macro_rules! test_parse_table_constraint {
($dialect:expr, $input:expr, $expected:expr $(,)?) => {{
($dialect:expr_2021, $input:expr_2021, $expected:expr_2021 $(,)?) => {{
$dialect.run_parser_method(&*$input, |parser| {
let constraint = parser.parse_optional_table_constraint().unwrap().unwrap();
// Validate that the structure is the same as expected
Expand Down Expand Up @@ -15255,7 +15255,7 @@ mod tests {
#[test]
fn test_parse_multipart_identifier_negative() {
macro_rules! test_parse_multipart_identifier_error {
($input:expr, $expected_err:expr $(,)?) => {{
($input:expr_2021, $expected_err:expr_2021 $(,)?) => {{
all_dialects().run_parser_method(&*$input, |parser| {
let actual_err = parser.parse_multipart_identifier().unwrap_err();
assert_eq!(actual_err.to_string(), $expected_err);
Expand Down
9 changes: 5 additions & 4 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,11 @@ pub fn assert_eq_vec<T: ToString>(expected: &[&str], actual: &[T]) {

pub fn only<T>(v: impl IntoIterator<Item = T>) -> T {
let mut iter = v.into_iter();
if let (Some(item), None) = (iter.next(), iter.next()) {
item
} else {
panic!("only called on collection without exactly one item")
match (iter.next(), iter.next()) {
(Some(item), None) => item,
_ => {
panic!("only called on collection without exactly one item")
}
}
}

Expand Down
42 changes: 21 additions & 21 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,26 @@ impl fmt::Display for Token {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Token::EOF => f.write_str("EOF"),
Token::Word(ref w) => write!(f, "{w}"),
Token::Number(ref n, l) => write!(f, "{}{long}", n, long = if *l { "L" } else { "" }),
Token::Char(ref c) => write!(f, "{c}"),
Token::SingleQuotedString(ref s) => write!(f, "'{s}'"),
Token::TripleSingleQuotedString(ref s) => write!(f, "'''{s}'''"),
Token::DoubleQuotedString(ref s) => write!(f, "\"{s}\""),
Token::TripleDoubleQuotedString(ref s) => write!(f, "\"\"\"{s}\"\"\""),
Token::DollarQuotedString(ref s) => write!(f, "{s}"),
Token::NationalStringLiteral(ref s) => write!(f, "N'{s}'"),
Token::EscapedStringLiteral(ref s) => write!(f, "E'{s}'"),
Token::UnicodeStringLiteral(ref s) => write!(f, "U&'{s}'"),
Token::HexStringLiteral(ref s) => write!(f, "X'{s}'"),
Token::SingleQuotedByteStringLiteral(ref s) => write!(f, "B'{s}'"),
Token::TripleSingleQuotedByteStringLiteral(ref s) => write!(f, "B'''{s}'''"),
Token::DoubleQuotedByteStringLiteral(ref s) => write!(f, "B\"{s}\""),
Token::TripleDoubleQuotedByteStringLiteral(ref s) => write!(f, "B\"\"\"{s}\"\"\""),
Token::SingleQuotedRawStringLiteral(ref s) => write!(f, "R'{s}'"),
Token::DoubleQuotedRawStringLiteral(ref s) => write!(f, "R\"{s}\""),
Token::TripleSingleQuotedRawStringLiteral(ref s) => write!(f, "R'''{s}'''"),
Token::TripleDoubleQuotedRawStringLiteral(ref s) => write!(f, "R\"\"\"{s}\"\"\""),
Token::Word(w) => write!(f, "{w}"),
Token::Number(n, l) => write!(f, "{}{long}", n, long = if *l { "L" } else { "" }),
Token::Char(c) => write!(f, "{c}"),
Token::SingleQuotedString(s) => write!(f, "'{s}'"),
Token::TripleSingleQuotedString(s) => write!(f, "'''{s}'''"),
Token::DoubleQuotedString(s) => write!(f, "\"{s}\""),
Token::TripleDoubleQuotedString(s) => write!(f, "\"\"\"{s}\"\"\""),
Token::DollarQuotedString(s) => write!(f, "{s}"),
Token::NationalStringLiteral(s) => write!(f, "N'{s}'"),
Token::EscapedStringLiteral(s) => write!(f, "E'{s}'"),
Token::UnicodeStringLiteral(s) => write!(f, "U&'{s}'"),
Token::HexStringLiteral(s) => write!(f, "X'{s}'"),
Token::SingleQuotedByteStringLiteral(s) => write!(f, "B'{s}'"),
Token::TripleSingleQuotedByteStringLiteral(s) => write!(f, "B'''{s}'''"),
Token::DoubleQuotedByteStringLiteral(s) => write!(f, "B\"{s}\""),
Token::TripleDoubleQuotedByteStringLiteral(s) => write!(f, "B\"\"\"{s}\"\"\""),
Token::SingleQuotedRawStringLiteral(s) => write!(f, "R'{s}'"),
Token::DoubleQuotedRawStringLiteral(s) => write!(f, "R\"{s}\""),
Token::TripleSingleQuotedRawStringLiteral(s) => write!(f, "R'''{s}'''"),
Token::TripleDoubleQuotedRawStringLiteral(s) => write!(f, "R\"\"\"{s}\"\"\""),
Token::Comma => f.write_str(","),
Token::Whitespace(ws) => write!(f, "{ws}"),
Token::DoubleEq => f.write_str("=="),
Expand Down Expand Up @@ -368,7 +368,7 @@ impl fmt::Display for Token {
Token::TildeEqual => f.write_str("~="),
Token::ShiftLeftVerticalBar => f.write_str("<<|"),
Token::VerticalBarShiftRight => f.write_str("|>>"),
Token::Placeholder(ref s) => write!(f, "{s}"),
Token::Placeholder(s) => write!(f, "{s}"),
Token::Arrow => write!(f, "->"),
Token::LongArrow => write!(f, "->>"),
Token::HashArrow => write!(f, "#>"),
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlparser_clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ fn parse_select_parametric_function() {
match &projection[0] {
UnnamedExpr(Expr::Function(f)) => {
let args = match &f.args {
FunctionArguments::List(ref args) => args,
FunctionArguments::List(args) => args,
_ => unreachable!(),
};
assert_eq!(args.args.len(), 2);
Expand Down
25 changes: 12 additions & 13 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,8 @@ fn parse_column_aliases() {
let sql = "SELECT a.col + 1 AS newname FROM foo AS a";
let select = verified_only_select(sql);
if let SelectItem::ExprWithAlias {
expr: Expr::BinaryOp {
ref op, ref right, ..
},
ref alias,
expr: Expr::BinaryOp { op, right, .. },
alias,
} = only(&select.projection)
{
assert_eq!(&BinaryOperator::Plus, op);
Expand Down Expand Up @@ -3280,16 +3278,17 @@ fn test_double_value() {

for (input, expected) in test_cases {
for (i, expr) in input.iter().enumerate() {
if let Statement::Query(query) =
dialects.one_statement_parses_to(&format!("SELECT {}", expr), "")
{
if let SetExpr::Select(select) = *query.body {
assert_eq!(expected[i], select.projection[0]);
} else {
match dialects.one_statement_parses_to(&format!("SELECT {}", expr), "") {
Statement::Query(query) => {
if let SetExpr::Select(select) = *query.body {
assert_eq!(expected[i], select.projection[0]);
} else {
panic!("Expected a SELECT statement");
}
}
_ => {
panic!("Expected a SELECT statement");
}
} else {
panic!("Expected a SELECT statement");
}
}
}
Expand Down Expand Up @@ -7071,7 +7070,7 @@ fn parse_ctes() {
let sql = &format!("SELECT ({with})");
let select = verified_only_select(sql);
match expr_from_projection(only(&select.projection)) {
Expr::Subquery(ref subquery) => {
Expr::Subquery(subquery) => {
assert_ctes_in_select(&cte_sqls, subquery.as_ref());
}
_ => panic!("Expected: subquery"),
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlparser_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sqlparser::dialect::GenericDialect;
use sqlparser::parser::Parser;

macro_rules! tpch_tests {
($($name:ident: $value:expr,)*) => {
($($name:ident: $value:expr_2021,)*) => {
const QUERIES: &[&str] = &[
$(include_str!(concat!("queries/tpch/", $value, ".sql"))),*
];
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use sqlparser::test_utils::*;

#[macro_export]
macro_rules! nest {
($base:expr $(, $join:expr)*) => {
($base:expr_2021 $(, $join:expr_2021)*) => {
TableFactor::NestedJoin { table_with_joins: Box::new(TableWithJoins {
relation: $base,
joins: vec![$(join($join)),*]
Expand Down
Loading