Skip to content

Commit f9ea25c

Browse files
authored
Add #![deny(clippy::all)] to all lib.rs (#453)
* Add lint `#![deny(clippy::all)]` * Automatic fixes from `cargo clippy --fix --all-features; cargo fmt` * Clean-up based on some clippy recommendations
1 parent 6d31b39 commit f9ea25c

File tree

52 files changed

+596
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+596
-488
lines changed

extension/partiql-extension-ion-functions/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(rust_2018_idioms)]
2+
#![deny(clippy::all)]
23

34
use ion_rs::data_source::ToIonDataSource;
45
use partiql_catalog::call_defs::{CallDef, CallSpec, CallSpecArg};
@@ -220,7 +221,10 @@ mod tests {
220221

221222
let parsed = parse(statement);
222223
let lowered = lower(&catalog, &parsed.expect("parse"));
223-
let bindings = env.as_ref().map(|e| (e).into()).unwrap_or_default();
224+
let bindings = env
225+
.as_ref()
226+
.map(std::convert::Into::into)
227+
.unwrap_or_default();
224228
let out = evaluate(&catalog, lowered, bindings);
225229

226230
assert!(out.is_bag());

extension/partiql-extension-ion/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// The encoding to use when decoding/encoding Ion to/from PartiQL [`partiql_value::Value`]
1+
/// The encoding to use when decoding/encoding Ion to/from `PartiQL` [`partiql_value::Value`]
22
#[derive(Copy, Clone, Eq, PartialEq)]
33
pub enum Encoding {
44
/// 'Unlifted'/'Unlowered' Ion to/from PartiQL [`partiql_value::Value`]. [`partiql_value::Value`]s that do not have a direct

extension/partiql-extension-ion/src/decode.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use std::str::FromStr;
1111
use thiserror::Error;
1212
use time::Duration;
1313

14-
use crate::common::*;
14+
use crate::common::{
15+
Encoding, BAG_ANNOT, DATE_ANNOT, MISSING_ANNOT, RE_SET_TIME_PARTS, TIME_ANNOT, TIME_PARTS_HOUR,
16+
TIME_PARTS_MINUTE, TIME_PARTS_SECOND, TIME_PARTS_TZ_HOUR, TIME_PARTS_TZ_MINUTE,
17+
};
1518

1619
/// Errors in ion decoding.
1720
///
@@ -63,6 +66,7 @@ pub struct IonDecoderConfig {
6366

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

8589
impl IonDecoderBuilder {
8690
/// Create the builder from 'config'
91+
#[must_use]
8792
pub fn new(config: IonDecoderConfig) -> Self {
8893
Self { config }
8994
}

extension/partiql-extension-ion/src/encode.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct IonEncoderConfig {
4545

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

6768
impl IonEncoderBuilder {
6869
/// Create the builder from 'config'
70+
#[must_use]
6971
pub fn new(config: IonEncoderConfig) -> Self {
7072
Self { config }
7173
}
@@ -214,7 +216,7 @@ where
214216
}
215217

216218
fn encode_decimal(&mut self, val: &Decimal) -> IonEncodeResult {
217-
let scale = val.scale() as i64;
219+
let scale = i64::from(val.scale());
218220
let mantissa = val.mantissa();
219221
let dec = ion_rs::Decimal::new(mantissa, -scale);
220222
Ok(self.writer.write_decimal(&dec)?)
@@ -234,9 +236,13 @@ where
234236
let ts = ion_rs::Timestamp::with_ymd(
235237
ts.year() as u32,
236238
ts.month() as u32,
237-
ts.day() as u32,
239+
u32::from(ts.day()),
240+
)
241+
.with_hms(
242+
u32::from(ts.hour()),
243+
u32::from(ts.minute()),
244+
u32::from(ts.second()),
238245
)
239-
.with_hms(ts.hour() as u32, ts.minute() as u32, ts.second() as u32)
240246
.with_nanoseconds(ts.nanosecond())
241247
.build_at_unknown_offset()?;
242248

@@ -246,11 +252,15 @@ where
246252
let ts = ion_rs::Timestamp::with_ymd(
247253
ts.year() as u32,
248254
ts.month() as u32,
249-
ts.day() as u32,
255+
u32::from(ts.day()),
256+
)
257+
.with_hms(
258+
u32::from(ts.hour()),
259+
u32::from(ts.minute()),
260+
u32::from(ts.second()),
250261
)
251-
.with_hms(ts.hour() as u32, ts.minute() as u32, ts.second() as u32)
252262
.with_nanoseconds(ts.nanosecond())
253-
.build_at_offset(ts.offset().whole_minutes() as i32)?;
263+
.build_at_offset(i32::from(ts.offset().whole_minutes()))?;
254264

255265
Ok(self.writer.write_timestamp(&ts)?)
256266
}
@@ -324,9 +334,12 @@ where
324334
self.inner
325335
.writer
326336
.set_annotations(std::iter::once(DATE_ANNOT));
327-
let ts =
328-
ion_rs::Timestamp::with_ymd(date.year() as u32, date.month() as u32, date.day() as u32)
329-
.build()?;
337+
let ts = ion_rs::Timestamp::with_ymd(
338+
date.year() as u32,
339+
date.month() as u32,
340+
u32::from(date.day()),
341+
)
342+
.build()?;
330343

331344
Ok(self.inner.writer.write_timestamp(&ts)?)
332345
}
@@ -336,19 +349,19 @@ where
336349
writer.set_annotations(std::iter::once(TIME_ANNOT));
337350
writer.step_in(IonType::Struct)?;
338351
writer.set_field_name(TIME_PART_HOUR_KEY);
339-
writer.write_i64(time.hour() as i64)?;
352+
writer.write_i64(i64::from(time.hour()))?;
340353
writer.set_field_name(TIME_PART_MINUTE_KEY);
341-
writer.write_i64(time.minute() as i64)?;
354+
writer.write_i64(i64::from(time.minute()))?;
342355
writer.set_field_name(TIME_PART_SECOND_KEY);
343356

344-
let seconds = Duration::new(time.second() as i64, time.nanosecond() as i32);
357+
let seconds = Duration::new(i64::from(time.second()), time.nanosecond() as i32);
345358
writer.write_f64(seconds.as_seconds_f64())?;
346359

347360
if let Some(offset) = offset {
348361
writer.set_field_name(TIME_PART_TZ_HOUR_KEY);
349-
writer.write_i64(offset.whole_hours() as i64)?;
362+
writer.write_i64(i64::from(offset.whole_hours()))?;
350363
writer.set_field_name(TIME_PART_TZ_MINUTE_KEY);
351-
writer.write_i64(offset.minutes_past_hour() as i64)?;
364+
writer.write_i64(i64::from(offset.minutes_past_hour()))?;
352365
}
353366

354367
writer.step_out()?;

extension/partiql-extension-ion/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(rust_2018_idioms)]
2+
#![deny(clippy::all)]
23

34
mod common;
45
pub mod decode;
@@ -180,7 +181,7 @@ mod tests {
180181
1,
181182
2,
182183
3,
183-
400000000,
184+
400_000_000,
184185
Some(30),
185186
),
186187
);
@@ -198,7 +199,7 @@ mod tests {
198199
1,
199200
2,
200201
3,
201-
400000000,
202+
400_000_000,
202203
None,
203204
),
204205
);
@@ -296,7 +297,7 @@ mod tests {
296297
1,
297298
2,
298299
3,
299-
400000000,
300+
400_000_000,
300301
Some(30),
301302
),
302303
);
@@ -314,7 +315,7 @@ mod tests {
314315
1,
315316
2,
316317
3,
317-
400000000,
318+
400_000_000,
318319
None,
319320
),
320321
);
@@ -330,7 +331,7 @@ mod tests {
330331
.build(),
331332
)
332333
.with_annotations(["$time"]),
333-
DateTime::from_hms_nano(12, 11, 10, 80000000),
334+
DateTime::from_hms_nano(12, 11, 10, 80_000_000),
334335
);
335336
assert_partiql_encoded_ion(
336337
"$time::{ hour: 12, minute: 11, second: 10.08, timezone_hour: 0, timezone_minute: 30}",
@@ -346,7 +347,7 @@ mod tests {
346347
.build(),
347348
)
348349
.with_annotations(["$time"]),
349-
DateTime::from_hms_nano_tz(12, 11, 10, 80000000, None, Some(30)),
350+
DateTime::from_hms_nano_tz(12, 11, 10, 80_000_000, None, Some(30)),
350351
);
351352
assert_partiql_encoded_ion(
352353
"$date::1957-05-25T",

extension/partiql-extension-visualize/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(rust_2018_idioms)]
2+
#![deny(clippy::all)]
23

34
#[cfg(feature = "visualize-dot")]
45
mod ast_to_dot;

partiql-ast-passes/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(rust_2018_idioms)]
2+
#![deny(clippy::all)]
23

3-
//! The PartiQL Abstract Syntax Tree (AST) passes.
4+
//! The `PartiQL` Abstract Syntax Tree (AST) passes.
45
//!
56
//! # Note
67
//!

partiql-ast-passes/src/name_resolver.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ impl<'c> NameResolver<'c> {
157157
let is_qnode = |typ, id| {
158158
self.enclosing_clause
159159
.get(&typ)
160-
.map(|nodes| nodes.contains(id))
161-
.unwrap_or(false)
160+
.is_some_and(|nodes| nodes.contains(id))
162161
};
163162
for id in self.id_path_to_root.iter().rev() {
164163
if is_qnode(EnclosingClause::Query, id) {
@@ -252,7 +251,11 @@ impl<'ast, 'c> Visitor<'ast> for NameResolver<'c> {
252251
produce_optional,
253252
} = keyrefs;
254253
let mut produce: Names = produce_required;
255-
produce.extend(produce_optional.iter().flat_map(|sym| sym.to_owned()));
254+
produce.extend(
255+
produce_optional
256+
.iter()
257+
.filter_map(std::borrow::ToOwned::to_owned),
258+
);
256259

257260
let schema = KeySchema { consume, produce };
258261

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

418421
self.enclosing_clause

partiql-ast-passes/src/partiql_typer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
125125
let ty = PartiqlType::new(kind);
126126
let id = *self.current_node();
127127
if let Some(c) = self.container_stack.last_mut() {
128-
c.push(ty.clone())
128+
c.push(ty.clone());
129129
}
130130
self.type_map.insert(id, ty);
131131
Traverse::Continue
@@ -165,7 +165,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
165165
self.type_map.insert(id, ty.clone());
166166

167167
if let Some(c) = self.container_stack.last_mut() {
168-
c.push(ty)
168+
c.push(ty);
169169
}
170170

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

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

211211
self.type_map.insert(id, ty.clone());
212212
if let Some(s) = self.container_stack.last_mut() {
213-
s.push(ty)
213+
s.push(ty);
214214
}
215215
Traverse::Continue
216216
}

partiql-ast/partiql-ast-macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(rust_2018_idioms)]
2+
#![deny(clippy::all)]
23

34
use darling::{FromDeriveInput, FromField, FromVariant};
45
use inflector::Inflector;

0 commit comments

Comments
 (0)