Skip to content

Commit bcd8751

Browse files
Box the remaining oversized enum variants and enforce large_enum_variant
1 parent a1727a5 commit bcd8751

19 files changed

Lines changed: 399 additions & 353 deletions

‎clippy.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
avoid-breaking-exported-api = false

‎src/ast/data_type.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum EnumMember {
3939
/// ClickHouse allows to specify an integer value for each enum value.
4040
///
4141
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/data-types/enum)
42-
NamedValue(String, Expr),
42+
NamedValue(String, Box<Expr>),
4343
}
4444

4545
/// SQL data types

‎src/ast/dcl.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! (commonly referred to as Data Control Language, or DCL)
2020
2121
#[cfg(not(feature = "std"))]
22-
use alloc::vec::Vec;
22+
use alloc::{boxed::Box, vec::Vec};
2323
use core::fmt;
2424

2525
#[cfg(feature = "serde")]
@@ -122,7 +122,7 @@ pub enum SetConfigValue {
122122
/// Use the current value (`FROM CURRENT`).
123123
FromCurrent,
124124
/// Set to the provided expression value.
125-
Value(Expr),
125+
Value(Box<Expr>),
126126
}
127127

128128
/// RESET config option:
@@ -175,7 +175,7 @@ pub enum AlterRoleOperation {
175175
/// Configuration name to set.
176176
config_name: ObjectName,
177177
/// Value to assign to the configuration.
178-
config_value: SetConfigValue,
178+
config_value: Box<SetConfigValue>,
179179
/// Optional database scope for the setting.
180180
in_database: Option<ObjectName>,
181181
},
@@ -215,7 +215,7 @@ impl fmt::Display for AlterRoleOperation {
215215
write!(f, "IN DATABASE {database_name} ")?;
216216
}
217217

218-
match config_value {
218+
match config_value.as_ref() {
219219
SetConfigValue::Default => write!(f, "SET {config_name} TO DEFAULT"),
220220
SetConfigValue::FromCurrent => write!(f, "SET {config_name} FROM CURRENT"),
221221
SetConfigValue::Value(expr) => write!(f, "SET {config_name} TO {expr}"),

‎src/ast/ddl.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ pub enum AlterPolicyOperation {
561561
/// Optional list of owners the policy applies to.
562562
to: Option<Vec<Owner>>,
563563
/// Optional `USING` expression for the policy.
564-
using: Option<Expr>,
564+
using: Option<Box<Expr>>,
565565
/// Optional `WITH CHECK` expression for the policy.
566-
with_check: Option<Expr>,
566+
with_check: Option<Box<Expr>>,
567567
},
568568
}
569569

@@ -1982,7 +1982,7 @@ pub enum ColumnOption {
19821982
/// ```
19831983
/// [MS SQL Server]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property
19841984
/// [Snowflake]: https://docs.snowflake.com/en/sql-reference/sql/create-table
1985-
Identity(IdentityPropertyKind),
1985+
Identity(Box<IdentityPropertyKind>),
19861986
/// SQLite specific: ON CONFLICT option on column definition
19871987
/// <https://www.sqlite.org/lang_conflict.html>
19881988
OnConflict(Keyword),
@@ -2770,7 +2770,7 @@ pub enum Deduplicate {
27702770
/// DEDUPLICATE ALL
27712771
All,
27722772
/// DEDUPLICATE BY expr
2773-
ByExpression(Expr),
2773+
ByExpression(Box<Expr>),
27742774
}
27752775

27762776
impl fmt::Display for Deduplicate {
@@ -3528,7 +3528,7 @@ impl fmt::Display for ForValues {
35283528
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
35293529
pub enum PartitionBoundValue {
35303530
/// An expression representing a partition bound value.
3531-
Expr(Expr),
3531+
Expr(Box<Expr>),
35323532
/// Represents negative infinity in partition bounds.
35333533
MinValue,
35343534
/// Represents positive infinity in partition bounds.

‎src/ast/dml.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ pub struct MultiTableInsertValues {
934934
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
935935
pub enum MultiTableInsertValue {
936936
/// A column reference or expression from the source
937-
Expr(Expr),
937+
Expr(Box<Expr>),
938938
/// The DEFAULT keyword
939939
Default,
940940
}

‎src/ast/mod.rs‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,9 @@ pub enum Subscript {
14401440
/// Optional lower bound for the slice (inclusive).
14411441
lower_bound: Option<Expr>,
14421442
/// Optional upper bound for the slice (inclusive).
1443-
upper_bound: Option<Expr>,
1443+
upper_bound: Option<Box<Expr>>,
14441444
/// Optional stride for the slice (step size).
1445-
stride: Option<Expr>,
1445+
stride: Option<Box<Expr>>,
14461446
},
14471447
}
14481448

@@ -1474,14 +1474,17 @@ impl fmt::Display for Subscript {
14741474

14751475
/// An element of a [`Expr::CompoundFieldAccess`].
14761476
/// It can be an expression or a subscript.
1477+
// Dot(Expr) cannot be boxed: it is used in deeply-nested patterns such as
1478+
// `AccessExpr::Dot(Expr::Function(..))` and as a fn-pointer via `.map(AccessExpr::Dot)`.
1479+
#[allow(clippy::large_enum_variant)]
14771480
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
14781481
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14791482
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
14801483
pub enum AccessExpr {
14811484
/// Accesses a field using dot notation, e.g. `foo.bar.baz`.
14821485
Dot(Expr),
14831486
/// Accesses a field or array element using bracket notation, e.g. `foo['bar']`.
1484-
Subscript(Subscript),
1487+
Subscript(Box<Subscript>),
14851488
}
14861489

14871490
impl fmt::Display for AccessExpr {
@@ -2588,7 +2591,7 @@ impl fmt::Display for CommentObject {
25882591
/// Password specification variants used in user-related statements.
25892592
pub enum Password {
25902593
/// A concrete password expression.
2591-
Password(Expr),
2594+
Password(Box<Expr>),
25922595
/// Represents a `NULL` password.
25932596
NullPassword,
25942597
}
@@ -6813,7 +6816,7 @@ pub enum MinMaxValue {
68136816
/// NO MINVALUE / NO MAXVALUE.
68146817
None,
68156818
/// `MINVALUE <expr>` / `MAXVALUE <expr>`.
6816-
Some(Expr),
6819+
Some(Box<Expr>),
68176820
}
68186821

68196822
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -6825,7 +6828,7 @@ pub enum OnInsert {
68256828
/// ON DUPLICATE KEY UPDATE (MySQL when the key already exists, then execute an update instead)
68266829
DuplicateKeyUpdate(Vec<Assignment>),
68276830
/// ON CONFLICT is a PostgreSQL and Sqlite extension
6828-
OnConflict(OnConflict),
6831+
OnConflict(Box<OnConflict>),
68296832
}
68306833

68316834
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -6878,7 +6881,7 @@ pub enum OnConflictAction {
68786881
/// Do nothing on conflict.
68796882
DoNothing,
68806883
/// Perform an update on conflict.
6881-
DoUpdate(DoUpdate),
6884+
DoUpdate(Box<DoUpdate>),
68826885
}
68836886

68846887
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -9343,7 +9346,7 @@ pub enum ShowStatementFilter {
93439346
/// Filter using ILIKE pattern.
93449347
ILike(String),
93459348
/// Filter using a WHERE expression.
9346-
Where(Expr),
9349+
Where(Box<Expr>),
93479350
/// Filter provided without a keyword (raw string).
93489351
NoKeyword(String),
93499352
}
@@ -10333,7 +10336,7 @@ pub enum CreateFunctionBody {
1033310336
/// AS 'MODULE_PATHNAME', 'cas_in_wrapper'
1033410337
/// ```
1033510338
/// [PostgreSQL]: https://www.postgresql.org/docs/current/sql-createfunction.html
10336-
link_symbol: Option<Expr>,
10339+
link_symbol: Option<Box<Expr>>,
1033710340
},
1033810341
/// A function body expression using the 'AS' keyword and shows up
1033910342
/// after any `OPTIONS` clause.
@@ -10397,7 +10400,7 @@ pub enum CreateFunctionBody {
1039710400
/// ```
1039810401
///
1039910402
/// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql?view=sql-server-ver16#select_stmt
10400-
AsReturnSelect(Select),
10403+
AsReturnSelect(Box<Select>),
1040110404
}
1040210405

1040310406
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -10464,7 +10467,7 @@ impl fmt::Display for MacroArg {
1046410467
/// Definition for a DuckDB macro: either an expression or a table-producing query.
1046510468
pub enum MacroDefinition {
1046610469
/// The macro is defined as an expression.
10467-
Expr(Expr),
10470+
Expr(Box<Expr>),
1046810471
/// The macro is defined as a table (query).
1046910472
Table(Box<Query>),
1047010473
}
@@ -11206,7 +11209,7 @@ pub enum TableObject {
1120611209
/// INSERT INTO TABLE FUNCTION remote('localhost', default.simple_table)
1120711210
/// ```
1120811211
/// [Clickhouse](https://clickhouse.com/docs/en/sql-reference/table-functions)
11209-
TableFunction(Function),
11212+
TableFunction(Box<Function>),
1121011213

1121111214
/// Table specified through a sub-query
1121211215
/// Example:

‎src/ast/query.rs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ pub enum SelectItemQualifiedWildcardKind {
854854
ObjectName(ObjectName),
855855
/// Select star on an arbitrary expression.
856856
/// e.g. `STRUCT<STRING>('foo').*`
857-
Expr(Expr),
857+
Expr(Box<Expr>),
858858
}
859859

860860
/// One item of the comma-separated list following `SELECT`
@@ -1139,7 +1139,7 @@ impl fmt::Display for ExceptSelectItem {
11391139
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11401140
pub struct ReplaceSelectItem {
11411141
/// List of replacement elements contained in the `REPLACE(...)` clause.
1142-
pub items: Vec<Box<ReplaceSelectElement>>,
1142+
pub items: Vec<ReplaceSelectElement>,
11431143
}
11441144

11451145
impl fmt::Display for ReplaceSelectItem {
@@ -1482,7 +1482,7 @@ pub enum TableFactor {
14821482
with_hints: Vec<Expr>,
14831483
/// Optional version qualifier to facilitate table time-travel, as
14841484
/// supported by BigQuery and MSSQL.
1485-
version: Option<TableVersion>,
1485+
version: Option<Box<TableVersion>>,
14861486
// Optional table function modifier to generate the ordinality for column.
14871487
/// For example, `SELECT * FROM generate_series(1, 10) WITH ORDINALITY AS t(a, b);`
14881488
/// [WITH ORDINALITY](https://www.postgresql.org/docs/current/functions-srf.html), supported by Postgres.
@@ -2649,9 +2649,9 @@ pub enum TableVersion {
26492649
/// The `CHANGES(INFORMATION => ...)` function-call expression.
26502650
changes: Expr,
26512651
/// The `AT(TIMESTAMP => ...)` function-call expression.
2652-
at: Expr,
2652+
at: Box<Expr>,
26532653
/// The optional `END(TIMESTAMP => ...)` function-call expression.
2654-
end: Option<Expr>,
2654+
end: Option<Box<Expr>>,
26552655
},
26562656
}
26572657

@@ -2866,9 +2866,9 @@ pub enum JoinOperator {
28662866
/// See <https://docs.snowflake.com/en/sql-reference/constructs/asof-join>.
28672867
AsOf {
28682868
/// Condition used to match records in the `ASOF` join.
2869-
match_condition: Expr,
2869+
match_condition: Box<Expr>,
28702870
/// Additional constraint applied to the `ASOF` join.
2871-
constraint: JoinConstraint,
2871+
constraint: Box<JoinConstraint>,
28722872
},
28732873
/// `STRAIGHT_JOIN` (MySQL non-standard behavior)
28742874
///
@@ -2890,7 +2890,7 @@ pub enum JoinOperator {
28902890
/// Represents how two tables are constrained in a join: `ON`, `USING`, `NATURAL`, or none.
28912891
pub enum JoinConstraint {
28922892
/// `ON <expr>` join condition.
2893-
On(Expr),
2893+
On(Box<Expr>),
28942894
/// `USING(...)` list of column names.
28952895
Using(Vec<ObjectName>),
28962896
/// `NATURAL` join (columns matched automatically).
@@ -3396,7 +3396,7 @@ pub enum PipeOperator {
33963396
/// Syntax: `|> [JOIN_TYPE] JOIN <table> [alias] ON <condition>` or `|> [JOIN_TYPE] JOIN <table> [alias] USING (<columns>)`
33973397
///
33983398
/// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#join_pipe_operator>
3399-
Join(Join),
3399+
Join(Box<Join>),
34003400
}
34013401

34023402
impl fmt::Display for PipeOperator {
@@ -3680,7 +3680,7 @@ pub struct Top {
36803680
/// Quantity used in a `TOP` clause: either an expression or a constant.
36813681
pub enum TopQuantity {
36823682
/// A parenthesized expression (MSSQL syntax: `TOP (expr)`).
3683-
Expr(Expr),
3683+
Expr(Box<Expr>),
36843684
/// An unparenthesized integer constant: `TOP 10`.
36853685
Constant(u64),
36863686
}
@@ -3788,7 +3788,7 @@ pub enum GroupByWithModifier {
37883788
/// Hive supports GROUPING SETS syntax, e.g. `GROUP BY GROUPING SETS(...)`.
37893789
///
37903790
/// [Hive]: <https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=30151323#EnhancedAggregation,Cube,GroupingandRollup-GROUPINGSETSclause>
3791-
GroupingSets(Expr),
3791+
GroupingSets(Box<Expr>),
37923792
}
37933793

37943794
impl fmt::Display for GroupByWithModifier {
@@ -4061,7 +4061,7 @@ impl fmt::Display for ForJson {
40614061
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
40624062
pub enum JsonTableColumn {
40634063
/// A named column with a JSON path
4064-
Named(JsonTableNamedColumn),
4064+
Named(Box<JsonTableNamedColumn>),
40654065
/// The FOR ORDINALITY column, which is a special column that returns the index of the current row in a JSON array.
40664066
ForOrdinality(Ident),
40674067
/// A set of nested columns, which extracts data from a nested JSON array.
@@ -4268,9 +4268,9 @@ pub enum XmlTableColumnOption {
42684268
/// The type of the column to be extracted.
42694269
r#type: DataType,
42704270
/// The path to the column to be extracted. If None, defaults to the column name.
4271-
path: Option<Expr>,
4271+
path: Option<Box<Expr>>,
42724272
/// Default value if path does not match
4273-
default: Option<Expr>,
4273+
default: Option<Box<Expr>>,
42744274
/// Whether the column is nullable (NULL=true, NOT NULL=false)
42754275
nullable: bool,
42764276
},

‎src/dialect/snowflake.rs‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,15 @@ impl Dialect for SnowflakeDialect {
418418
let with = parser.parse_keyword(Keyword::WITH);
419419

420420
if parser.parse_keyword(Keyword::IDENTITY) {
421-
Ok(parse_identity_property(parser)
422-
.map(|p| Some(ColumnOption::Identity(IdentityPropertyKind::Identity(p)))))
421+
Ok(parse_identity_property(parser).map(|p| {
422+
Some(ColumnOption::Identity(Box::new(
423+
IdentityPropertyKind::Identity(p),
424+
)))
425+
}))
423426
} else if parser.parse_keyword(Keyword::AUTOINCREMENT) {
424427
Ok(parse_identity_property(parser).map(|p| {
425-
Some(ColumnOption::Identity(IdentityPropertyKind::Autoincrement(
426-
p,
428+
Some(ColumnOption::Identity(Box::new(
429+
IdentityPropertyKind::Autoincrement(p),
427430
)))
428431
}))
429432
} else if parser.parse_keywords(&[Keyword::MASKING, Keyword::POLICY]) {
@@ -1943,7 +1946,7 @@ fn parse_multi_table_insert_value(
19431946
if parser.parse_keyword(Keyword::DEFAULT) {
19441947
Ok(MultiTableInsertValue::Default)
19451948
} else {
1946-
Ok(MultiTableInsertValue::Expr(parser.parse_expr()?))
1949+
Ok(MultiTableInsertValue::Expr(Box::new(parser.parse_expr()?)))
19471950
}
19481951
}
19491952

‎src/lib.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,9 @@
149149
150150
#![cfg_attr(not(feature = "std"), no_std)]
151151
#![allow(clippy::upper_case_acronyms)]
152-
// Permit large enum variants to keep a unified, expressive AST.
153-
// Splitting complex nodes (expressions, statements, types) into separate types
154-
// would bloat the API and hide intent. Extra memory is a worthwhile tradeoff.
155-
#![allow(clippy::large_enum_variant)]
152+
// `avoid-breaking-exported-api = false` in clippy.toml exists to catch oversized
153+
// enum variants; it also unmutes naming lints on the public API, which are not wanted.
154+
#![allow(clippy::enum_variant_names)]
156155
#![forbid(clippy::unreachable)]
157156
#![forbid(missing_docs)]
158157

0 commit comments

Comments
 (0)