Skip to content
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

Add #![deny(clippy::all)] to all lib.rs #453

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion extension/partiql-extension-ion-functions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

use ion_rs::data_source::ToIonDataSource;
use partiql_catalog::call_defs::{CallDef, CallSpec, CallSpecArg};
Expand Down Expand Up @@ -220,7 +221,10 @@ mod tests {

let parsed = parse(statement);
let lowered = lower(&catalog, &parsed.expect("parse"));
let bindings = env.as_ref().map(|e| (e).into()).unwrap_or_default();
let bindings = env
.as_ref()
.map(std::convert::Into::into)
.unwrap_or_default();
let out = evaluate(&catalog, lowered, bindings);

assert!(out.is_bag());
Expand Down
2 changes: 1 addition & 1 deletion extension/partiql-extension-ion/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// The encoding to use when decoding/encoding Ion to/from PartiQL [`partiql_value::Value`]
/// The encoding to use when decoding/encoding Ion to/from `PartiQL` [`partiql_value::Value`]
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum Encoding {
/// 'Unlifted'/'Unlowered' Ion to/from PartiQL [`partiql_value::Value`]. [`partiql_value::Value`]s that do not have a direct
Expand Down
7 changes: 6 additions & 1 deletion extension/partiql-extension-ion/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use std::str::FromStr;
use thiserror::Error;
use time::Duration;

use crate::common::*;
use crate::common::{
Encoding, BAG_ANNOT, DATE_ANNOT, MISSING_ANNOT, RE_SET_TIME_PARTS, TIME_ANNOT, TIME_PARTS_HOUR,
TIME_PARTS_MINUTE, TIME_PARTS_SECOND, TIME_PARTS_TZ_HOUR, TIME_PARTS_TZ_MINUTE,
};

/// Errors in ion decoding.
///
Expand Down Expand Up @@ -63,6 +66,7 @@ pub struct IonDecoderConfig {

impl IonDecoderConfig {
/// Set the mode to `mode`
#[must_use]
pub fn with_mode(mut self, mode: crate::Encoding) -> Self {
self.mode = mode;
self
Expand All @@ -84,6 +88,7 @@ pub struct IonDecoderBuilder {

impl IonDecoderBuilder {
/// Create the builder from 'config'
#[must_use]
pub fn new(config: IonDecoderConfig) -> Self {
Self { config }
}
Expand Down
41 changes: 27 additions & 14 deletions extension/partiql-extension-ion/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct IonEncoderConfig {

impl IonEncoderConfig {
/// Set the mode to `mode`
#[must_use]
pub fn with_mode(mut self, mode: crate::Encoding) -> Self {
self.mode = mode;
self
Expand All @@ -66,6 +67,7 @@ pub struct IonEncoderBuilder {

impl IonEncoderBuilder {
/// Create the builder from 'config'
#[must_use]
pub fn new(config: IonEncoderConfig) -> Self {
Self { config }
}
Expand Down Expand Up @@ -214,7 +216,7 @@ where
}

fn encode_decimal(&mut self, val: &Decimal) -> IonEncodeResult {
let scale = val.scale() as i64;
let scale = i64::from(val.scale());
let mantissa = val.mantissa();
let dec = ion_rs::Decimal::new(mantissa, -scale);
Ok(self.writer.write_decimal(&dec)?)
Expand All @@ -234,9 +236,13 @@ where
let ts = ion_rs::Timestamp::with_ymd(
ts.year() as u32,
ts.month() as u32,
ts.day() as u32,
u32::from(ts.day()),
)
.with_hms(
u32::from(ts.hour()),
u32::from(ts.minute()),
u32::from(ts.second()),
)
.with_hms(ts.hour() as u32, ts.minute() as u32, ts.second() as u32)
.with_nanoseconds(ts.nanosecond())
.build_at_unknown_offset()?;

Expand All @@ -246,11 +252,15 @@ where
let ts = ion_rs::Timestamp::with_ymd(
ts.year() as u32,
ts.month() as u32,
ts.day() as u32,
u32::from(ts.day()),
)
.with_hms(
u32::from(ts.hour()),
u32::from(ts.minute()),
u32::from(ts.second()),
)
.with_hms(ts.hour() as u32, ts.minute() as u32, ts.second() as u32)
.with_nanoseconds(ts.nanosecond())
.build_at_offset(ts.offset().whole_minutes() as i32)?;
.build_at_offset(i32::from(ts.offset().whole_minutes()))?;

Ok(self.writer.write_timestamp(&ts)?)
}
Expand Down Expand Up @@ -324,9 +334,12 @@ where
self.inner
.writer
.set_annotations(std::iter::once(DATE_ANNOT));
let ts =
ion_rs::Timestamp::with_ymd(date.year() as u32, date.month() as u32, date.day() as u32)
.build()?;
let ts = ion_rs::Timestamp::with_ymd(
date.year() as u32,
date.month() as u32,
u32::from(date.day()),
)
.build()?;

Ok(self.inner.writer.write_timestamp(&ts)?)
}
Expand All @@ -336,19 +349,19 @@ where
writer.set_annotations(std::iter::once(TIME_ANNOT));
writer.step_in(IonType::Struct)?;
writer.set_field_name(TIME_PART_HOUR_KEY);
writer.write_i64(time.hour() as i64)?;
writer.write_i64(i64::from(time.hour()))?;
writer.set_field_name(TIME_PART_MINUTE_KEY);
writer.write_i64(time.minute() as i64)?;
writer.write_i64(i64::from(time.minute()))?;
writer.set_field_name(TIME_PART_SECOND_KEY);

let seconds = Duration::new(time.second() as i64, time.nanosecond() as i32);
let seconds = Duration::new(i64::from(time.second()), time.nanosecond() as i32);
writer.write_f64(seconds.as_seconds_f64())?;

if let Some(offset) = offset {
writer.set_field_name(TIME_PART_TZ_HOUR_KEY);
writer.write_i64(offset.whole_hours() as i64)?;
writer.write_i64(i64::from(offset.whole_hours()))?;
writer.set_field_name(TIME_PART_TZ_MINUTE_KEY);
writer.write_i64(offset.minutes_past_hour() as i64)?;
writer.write_i64(i64::from(offset.minutes_past_hour()))?;
}

writer.step_out()?;
Expand Down
13 changes: 7 additions & 6 deletions extension/partiql-extension-ion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

mod common;
pub mod decode;
Expand Down Expand Up @@ -180,7 +181,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
Some(30),
),
);
Expand All @@ -198,7 +199,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
None,
),
);
Expand Down Expand Up @@ -296,7 +297,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
Some(30),
),
);
Expand All @@ -314,7 +315,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
None,
),
);
Expand All @@ -330,7 +331,7 @@ mod tests {
.build(),
)
.with_annotations(["$time"]),
DateTime::from_hms_nano(12, 11, 10, 80000000),
DateTime::from_hms_nano(12, 11, 10, 80_000_000),
);
assert_partiql_encoded_ion(
"$time::{ hour: 12, minute: 11, second: 10.08, timezone_hour: 0, timezone_minute: 30}",
Expand All @@ -346,7 +347,7 @@ mod tests {
.build(),
)
.with_annotations(["$time"]),
DateTime::from_hms_nano_tz(12, 11, 10, 80000000, None, Some(30)),
DateTime::from_hms_nano_tz(12, 11, 10, 80_000_000, None, Some(30)),
);
assert_partiql_encoded_ion(
"$date::1957-05-25T",
Expand Down
1 change: 1 addition & 0 deletions extension/partiql-extension-visualize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

#[cfg(feature = "visualize-dot")]
mod ast_to_dot;
Expand Down
3 changes: 2 additions & 1 deletion partiql-ast-passes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

//! The PartiQL Abstract Syntax Tree (AST) passes.
//! The `PartiQL` Abstract Syntax Tree (AST) passes.
//!
//! # Note
//!
Expand Down
11 changes: 7 additions & 4 deletions partiql-ast-passes/src/name_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ impl<'c> NameResolver<'c> {
let is_qnode = |typ, id| {
self.enclosing_clause
.get(&typ)
.map(|nodes| nodes.contains(id))
.unwrap_or(false)
.is_some_and(|nodes| nodes.contains(id))
};
for id in self.id_path_to_root.iter().rev() {
if is_qnode(EnclosingClause::Query, id) {
Expand Down Expand Up @@ -252,7 +251,11 @@ impl<'ast, 'c> Visitor<'ast> for NameResolver<'c> {
produce_optional,
} = keyrefs;
let mut produce: Names = produce_required;
produce.extend(produce_optional.iter().flat_map(|sym| sym.to_owned()));
produce.extend(
produce_optional
.iter()
.filter_map(std::borrow::ToOwned::to_owned),
);

let schema = KeySchema { consume, produce };

Expand Down Expand Up @@ -412,7 +415,7 @@ impl<'ast, 'c> Visitor<'ast> for NameResolver<'c> {
{
self.errors.push(AstTransformError::IllegalState(
"group_key expects a FromLet enclosing clause".to_string(),
))
));
}

self.enclosing_clause
Expand Down
8 changes: 4 additions & 4 deletions partiql-ast-passes/src/partiql_typer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
let ty = PartiqlType::new(kind);
let id = *self.current_node();
if let Some(c) = self.container_stack.last_mut() {
c.push(ty.clone())
c.push(ty.clone());
}
self.type_map.insert(id, ty);
Traverse::Continue
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
self.type_map.insert(id, ty.clone());

if let Some(c) = self.container_stack.last_mut() {
c.push(ty)
c.push(ty);
}

Traverse::Continue
Expand All @@ -188,7 +188,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {

self.type_map.insert(id, ty.clone());
if let Some(s) = self.container_stack.last_mut() {
s.push(ty)
s.push(ty);
}
Traverse::Continue
}
Expand All @@ -210,7 +210,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {

self.type_map.insert(id, ty.clone());
if let Some(s) = self.container_stack.last_mut() {
s.push(ty)
s.push(ty);
}
Traverse::Continue
}
Expand Down
1 change: 1 addition & 0 deletions partiql-ast/partiql-ast-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

use darling::{FromDeriveInput, FromField, FromVariant};
use inflector::Inflector;
Expand Down
16 changes: 8 additions & 8 deletions partiql-ast/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! A PartiQL abstract syntax tree (AST).
//! A `PartiQL` abstract syntax tree (AST).
//!
//! This module contains the structures for the language AST.
//! Two main entities in the module are [`Item`] and [`AstNode`]. `AstNode` represents an AST node
//! and `Item` represents a PartiQL statement type, e.g. query, data definition language (DDL)
//! and `Item` represents a `PartiQL` statement type, e.g. query, data definition language (DDL)
//! data manipulation language (DML).

// As more changes to this AST are expected, unless explicitly advised, using the structures exposed
Expand Down Expand Up @@ -409,10 +409,10 @@ pub enum Expr {
Error,
}

/// `Lit` is mostly inspired by SQL-92 Literals standard and PartiQL specification.
/// `Lit` is mostly inspired by SQL-92 Literals standard and `PartiQL` specification.
/// See section 5.3 in the following:
/// <https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt>
/// and Section 2 of the following (Figure 1: BNF Grammar for PartiQL Values):
/// and Section 2 of the following (Figure 1: BNF Grammar for `PartiQL` Values):
/// <https://partiql.org/assets/PartiQL-Specification.pdf>
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -745,7 +745,7 @@ pub struct FromLet {
pub by_alias: Option<SymbolPrimitive>,
}

/// Indicates the type of FromLet, see the following for more details:
/// Indicates the type of `FromLet`, see the following for more details:
/// https:///github.com/partiql/partiql-lang-kotlin/issues/242
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -784,7 +784,7 @@ pub enum JoinSpec {
Natural,
}

/// GROUP BY <grouping_strategy> <group_key>[, <group_key>]... \[AS <symbol>\]
/// GROUP BY <`grouping_strategy`> <`group_key`>[, <`group_key`>]... \[AS <symbol>\]
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct GroupByExpr {
Expand Down Expand Up @@ -813,7 +813,7 @@ pub struct GroupKey {
pub as_alias: Option<SymbolPrimitive>,
}

/// ORDER BY <sort_spec>...
/// ORDER BY <`sort_spec`>...
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct OrderByExpr {
Expand Down Expand Up @@ -852,7 +852,7 @@ pub enum NullOrderingSpec {
Last,
}

/// Represents all possible PartiQL data types.
/// Represents all possible `PartiQL` data types.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Type {
Expand Down
3 changes: 2 additions & 1 deletion partiql-ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

//! The PartiQL Abstract Syntax Tree (AST).
//! The `PartiQL` Abstract Syntax Tree (AST).
//!
//! # Note
//!
Expand Down
6 changes: 3 additions & 3 deletions partiql-ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ mod tests {
impl<'ast> Visitor<'ast> for Accum {
fn enter_lit(&mut self, literal: &'ast Lit) -> Traverse {
match literal {
Lit::Int8Lit(l) => self.val.get_or_insert(0i64).add_assign(*l as i64),
Lit::Int16Lit(l) => self.val.get_or_insert(0i64).add_assign(*l as i64),
Lit::Int32Lit(l) => self.val.get_or_insert(0i64).add_assign(*l as i64),
Lit::Int8Lit(l) => self.val.get_or_insert(0i64).add_assign(i64::from(*l)),
Lit::Int16Lit(l) => self.val.get_or_insert(0i64).add_assign(i64::from(*l)),
Lit::Int32Lit(l) => self.val.get_or_insert(0i64).add_assign(i64::from(*l)),
Lit::Int64Lit(l) => self.val.get_or_insert(0i64).add_assign(l),
_ => {}
}
Expand Down
6 changes: 1 addition & 5 deletions partiql-catalog/src/call_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ pub struct CallDef {
}

impl CallDef {
pub fn lookup(
&self,
args: &Vec<CallArgument>,
name: &str,
) -> Result<ValueExpr, CallLookupError> {
pub fn lookup(&self, args: &[CallArgument], name: &str) -> Result<ValueExpr, CallLookupError> {
'overload: for overload in &self.overloads {
let formals = &overload.input;
if formals.len() != args.len() {
Expand Down
Loading
Loading